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

**URL:** <https://community.grafana.com/t/using-a-text-box-variable-as-an-elasticsearch-query-parameter/38161>\
**Category:** General\
**Tags:** elasticsearch\
**Created:** [October 19, 2020, 5:56pm UTC](https://community.grafana.com/t/using-a-text-box-variable-as-an-elasticsearch-query-parameter/38161 "2020-10-19T17:56:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillaumen](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@guillaumen](https://community.grafana.com/u/guillaumen)\
**Post date:** [October 19, 2020, 5:56pm UTC](https://community.grafana.com/t/using-a-text-box-variable-as-an-elasticsearch-query-parameter/38161/1 "2020-10-19T17:56:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sudonova](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sudonova](https://community.grafana.com/u/sudonova)\
**Post date:** [January 24, 2022, 6:40pm UTC](https://community.grafana.com/t/using-a-text-box-variable-as-an-elasticsearch-query-parameter/38161/2 "2022-01-24T18:40:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremycohensolal](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jeremycohensolal](https://community.grafana.com/u/jeremycohensolal)\
**Post date:** [February 19, 2025, 10:09am UTC](https://community.grafana.com/t/using-a-text-box-variable-as-an-elasticsearch-query-parameter/38161/3 "2025-02-19T10:09:23Z")

</div>

If someone found a hack for this… I’d like to have it!
