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:

blablabla

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.

2 Likes

Hi
This is a serious issue for elasticsearch data source. Can there be at least a coalesce function? That way we can set variable to * when user is not searching. Well elasticsearch is all about search isn’t it? Thanks