# Variable query doesn't work

**URL:** <https://community.grafana.com/t/variable-query-doesnt-work/5675>\
**Category:** Elasticsearch\
**Tags:** templating\
**Created:** [February 22, 2018, 3:06pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675 "2018-02-22T15:06:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![morv](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@morv](https://community.grafana.com/u/morv)\
**Post date:** [February 22, 2018, 3:06pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/1 "2018-02-22T15:06:15Z")

</div>

Hi,  
Im using Elasticsearch 6 and grafana 5.  
I’m trying to create a varibale of all the IP Addresses, using the field “IP”.  
This field is of type string.  
There is no error but also no output:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/c/c79440f009afa2cb72842becc7949dffec57e1ea.png)  
When i change it to field “@timestamp” i do see outputs (“Preview of values”)

Thanks in advance.

---

<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:** [February 23, 2018, 12:59pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/2 "2018-02-23T12:59:04Z")

</div>

Hi,

Have you created elastic data source in Grafana with version set? What does your index mappings look for the IP field in your documents? Thinking that you may need to specify that IP should be of type keyword in mapping and then use IP.keyword or similar in Grafana.

Marcus

---

<div class="post-metadata">

**Author:** ![davewaters](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/davewaters/32/7308_2.png) [@davewaters](https://community.grafana.com/u/davewaters)\
**Post date:** [February 23, 2018, 2:10pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/3 "2018-02-23T14:10:31Z")

</div>

I think it is case sensitive. You may need to switch IP to lowercase ip. I am on Elasticsearch 6.2 and Grafana 5 beta 4 and have this very query. I can confirm that it works properly for me.

Change your query to: {“find”:“fields”,“type”:“ip”}

mefraimsson is correct that you should also check your index mappings, to make sure you have fields with the IP type. A good way to further test this is also to change your query to: {“find”:“fields”} which should show you all of your fields, which from there you can ensure the query is properly completing.

---

<div class="post-metadata">

**Author:** ![morv](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@morv](https://community.grafana.com/u/morv)\
**Post date:** [February 25, 2018, 6:59am UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/4 "2018-02-25T06:59:45Z")

</div>

I changed it to {“find”: “terms”, “field”: “IP.keyword”} and it fixed it.  
Thank you!

---

<div class="post-metadata">

**Author:** ![davewaters](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/davewaters/32/7308_2.png) [@davewaters](https://community.grafana.com/u/davewaters)\
**Post date:** [February 26, 2018, 6:01pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/5 "2018-02-26T18:01:37Z")

</div>

Based on your results, it looks like you are saving your IP addresses into a keyword/ string field. You may want to investigate your index mapping, and adjust this to type:ip. Down the road, if you want to take advantage of Elasticsearch’s advanced search and aggregation functions for IP addresses (like IP range aggregation or CIDR based searches) you will need to store IP addresses as type:ip rather than type:keyword (your apparent, current mapping).

---

<div class="post-metadata">

**Author:** ![qhh0205](https://avatars.discourse-cdn.com/v4/letter/q/d26b3c/32.png) [@qhh0205](https://community.grafana.com/u/qhh0205)\
**Post date:** [June 6, 2018, 3:04pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/6 "2018-06-06T15:04:13Z")

</div>

I hava the same issue, no data found! It is confused… every config is right…

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/b/b9e07bd57122416b76c915386eb1865c30d5fb5b.png)  
 ![image](https://us1.discourse-cdn.com/grafana/original/2X/1/15da93d58c1c9a1d317fa5d03fbf92b87ff82671.png)

---

<div class="post-metadata">

**Author:** ![qhh0205](https://avatars.discourse-cdn.com/v4/letter/q/d26b3c/32.png) [@qhh0205](https://community.grafana.com/u/qhh0205)\
**Post date:** [June 6, 2018, 3:23pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/7 "2018-06-06T15:23:18Z")

</div>

I have know the reason, the index pattern is not right for me, so no data found, the following index pattern is not right:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/e/eb8905860434633465916878dff6f90b832e2c08.jpg)

The following is right(please note the [and] char):

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/3/3b9592efb436ee0ab688b87c720eaea10ebed1f0.jpg)

---

<div class="post-metadata">

**Author:** ![shkarlsson](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/shkarlsson/32/22335_2.png) [@shkarlsson](https://community.grafana.com/u/shkarlsson)\
**Post date:** [April 6, 2022, 12:29pm UTC](https://community.grafana.com/t/variable-query-doesnt-work/5675/8 "2022-04-06T12:29:27Z")

</div>

The solution for me was to put an asterix after my index name as so: index-name\* and use the query pattern below:

`{"find": "terms", "field": "very_secret_field.keyword"}`

```
¯\_(ツ)_/¯
```
