Using a "text box" variable as an Elasticsearch query parameter

Hi, I’m trying to build a dashboard in which users will be able to refine/filter the shown data by inputting some text in a text box.
My idea is to use this text box variable in my Elasticsearch query such as:

blablabla AND “$myTextBox”

I’m encountering an issue with this. When $myTextBox is empty, Elasticsearch returns different results than when this search criteria is absent:

blablabla AND “”

Is not processed by Elasticsearch as:


Is there a way in Grafana to circumvent this? For instance, by configuring my Grafana dashboard to only append [AND “$myTextBox” ] to my query if $myTextBox is not empty?

Otherwise, and this is an Elasticsearch question, is there a way to change my query so that Elasticsearch returns the same results for both queries?

Important note: I cannot use a “query” variable for this as I want this “filter string” to be searched against all of my Elasticsearch documents.

1 Like