# How to write query for a variable for an elasticsearch source?

**URL:** <https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003>\
**Category:** Configuration\
**Created:** [August 28, 2018, 10:06am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003 "2018-08-28T10:06:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityasmallcase](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@adityasmallcase](https://community.grafana.com/u/adityasmallcase)\
**Post date:** [August 28, 2018, 10:06am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/1 "2018-08-28T10:06:57Z")

</div>

In the dashboard settings, I want to create a variable so that I can have the option to see the metrics panel for that particular host. I cannot seem to figure out the correct query syntax for the fields that contains the host IP to be used as a variable. Can someone help on this?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [August 28, 2018, 11:09am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/2 "2018-08-28T11:09:22Z")

</div>

You need to use Lucene syntax.

---

<div class="post-metadata">

**Author:** ![adityasmallcase](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@adityasmallcase](https://community.grafana.com/u/adityasmallcase)\
**Post date:** [August 28, 2018, 11:17am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/3 "2018-08-28T11:17:05Z")

</div>

Okay, but the query field requires a json. I have a field named “tags.aws\_private\_ip” that holds the IP address. Putting the query in the json format gives me unexpected token error. Could you give me an example of what exactly should go into the query ?

---

<div class="post-metadata">

**Author:** ![anon34853223](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@anon34853223](https://community.grafana.com/u/anon34853223)\
**Post date:** [August 29, 2018, 12:55pm UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/4 "2018-08-29T12:55:24Z")

</div>

[http://docs.grafana.org/features/datasources/elasticsearch/#query-variable](http://docs.grafana.org/features/datasources/elasticsearch/#query-variable)

---

<div class="post-metadata">

**Author:** ![jawa](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@jawa](https://community.grafana.com/u/jawa)\
**Post date:** [April 4, 2022, 8:12am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/5 "2022-04-04T08:12:28Z")

</div>

Thanks. This helped alot!

---

<div class="post-metadata">

**Author:** ![satyarajpolirathi1](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@satyarajpolirathi1](https://community.grafana.com/u/satyarajpolirathi1)\
**Post date:** [August 30, 2022, 4:46am UTC](https://community.grafana.com/t/how-to-write-query-for-a-variable-for-an-elasticsearch-source/10003/6 "2022-08-30T04:46:15Z")

</div>

Will it be possible to query values like count or distinct count in the variables using ES?
