Only "All" Value Available For Template Variable Selection

I am trying to display data on a graph in grafana. However, when I add a new template variable, I am unable to preview all the values for that variable. The only one I’m seeing is the “all” value. Likewise, in the dropdown menus to select values for each template variable, I can only see the “all variable” as an option for each variable. I am also getting a query parsing exception when I try to query both of my template variables.

Any idea what the problem might be?

Can you show the query for your template variable?

{“find”: “terms”, “field”: “Serial Number”}

Is the data source Elasticsearch?

Yes, I am using elasticsearch as the database. I must be doing something wrong but I don’t know what it is.

Why do you have a space in your field name? That is unusual. Found this on the Elasticsearch forum:

Thank you for pointing out the spacing problem. I removed the space and updated the template variable but I am still having the problem.

Hard to say without more information. Can you check the raw query and response (here is a guide).

Here is an example on the demo site if you want to check that your query and the options for the template variable looks similar:

http://play.grafana.org/dashboard/db/elasticsearch-templated?orgId=1&editview=templating

My lookup does not have an “@” before the field name. Is this necessary? Also, I don’t understand why some variables have queries after the field lookup.

The response I get back from elasticsearch is as follows:

{“responses”:[{“error”:{“root_cause”:[{“type”:“query_parsing_exception”,“reason”:“Failed to parse query [SerialNumber:() AND NumberofAlohaBurstsReceived:()]”,“index”:“joeldncc-2017.06.14”,“line”:1,“col”:141},{“type”:“query_parsing_exception”,“reason”:“Failed to parse query [SerialNumber:() AND NumberofAlohaBurstsReceived:()]”,“index”:“joeldncc-2017.06.15”,“line”:1,“col”:141}],“type”:“search_phase_execution_exception”,“reason”:“all shards failed”,“phase”:“query”,“grouped”:true,“failed_shards”:[{“shard”:0,“index”:“joeldncc-2017.06.14”,“node”:“qyHnVcWrRXycI0-twro3Kg”,“reason”:{“type”:“query_parsing_exception”,“reason”:“Failed to parse query [SerialNumber:() AND NumberofAlohaBurstsReceived:()]”,“index”:“joeldncc-2017.06.14”,“line”:1,“col”:141,“caused_by”:{“type”:“parse_exception”,“reason”:"Cannot parse ‘SerialNumber:() AND NumberofAlohaBurstsReceived:()’: Encountered " “)” ") “” at line 1, column 14.\r\nWas expecting one of:\r\n …\r\n “+” …\r\n “-” …\r\n …\r\n “(” …\r\n “" …\r\n …\r\n …\r\n …\r\n …\r\n …\r\n “[” …\r\n “{” …\r\n …\r\n …\r\n "” …\r\n ",“caused_by”:{“type”:“parse_exception”,“reason”:"Encountered " “)” ") “” at line 1, column 14.\r\nWas expecting one of:\r\n …\r\n “+” …\r\n “-” …\r\n …\r\n “(” …\r\n “" …\r\n …\r\n …\r\n …\r\n …\r\n …\r\n “[” …\r\n “{” …\r\n …\r\n …\r\n "” …\r\n "}}}},{“shard”:0,“index”:“joeldncc-2017.06.15”,“node”:“qyHnVcWrRXycI0-twro3Kg”,“reason”:{“type”:“query_parsing_exception”,“reason”:“Failed to parse query [SerialNumber:() AND NumberofAlohaBurstsReceived:()]”,“index”:“joeldncc-2017.06.15”,“line”:1,“col”:141,“caused_by”:{“type”:“parse_exception”,“reason”:"Cannot parse ‘SerialNumber:() AND NumberofAlohaBurstsReceived:()’: Encountered " “)” ") “” at line 1, column 14.\r\nWas expecting one of:\r\n …\r\n “+” …\r\n “-” …\r\n …\r\n “(” …\r\n “" …\r\n …\r\n …\r\n …\r\n …\r\n …\r\n “[” …\r\n “{” …\r\n …\r\n …\r\n "” …\r\n ",“caused_by”:{“type”:“parse_exception”,“reason”:"Encountered " “)” ") “” at line 1, column 14.\r\nWas expecting one of:\r\n …\r\n “+” …\r\n “-” …\r\n …\r\n “(” …\r\n “" …\r\n …\r\n …\r\n …\r\n …\r\n …\r\n “[” …\r\n “{” …\r\n …\r\n …\r\n "” …\r\n "}}}}]}}]}

Are we talking about the Template Variable query here? Or the metric query?

I assumed you meant the query for the Template Variable:

Can you provide a few more screenshots or describe more what the problem is.

I meant the template variable query, because I assumed that’s what was causing the metric query to break. But maybe I should take a look at the metric query. My metric query is the following:

SerialNumber:$SerialNumber AND NumberofAlohaBurstsReceived:$NumberofAlohaBurstsReceived

What do the “@” symbols do? I am quite new to lucene queries.

Also, in the template queries, why is there a “query” after some of the field lookups. Here’s an example from the sample grafana installation that you linked to:

{“find”: “terms”, “field”: “@hostname”, “query”: “@source:$source”}

Why is this necessary?

@ symbol is just a convention - doesn’t mean anything really: amazon web services - Elasticsearch : Meaning of "@" symbol - Stack Overflow

$source is an example of chaining template variables (the query means choosing a value in one dropdown affects the list of options in another template variable dropdown): Elasticsearch data source | Grafana documentation

Things to check:

  • Are your fieldnames correct?
  • Is your data source set up correctly with the correct version of Elasticsearch and the correct index?
  • Look at the raw queries for the two template variables in the network tab, do they look correct?

Fieldnames are correct. Data source is set up correctly. I can visibly see the index in the data folder of elasticsearch. I don’t have much experience with queries so I can’t say much about that unfortunately.

If you hard code the values in the metric query, does it work? Have you figured out why your template variable queries do not return any values?

If I hard code the values, I get the following:

{
“root_cause”: [
{
“type”: “number_format_exception”,
“reason”: “For input string: “NumberofAlohaBurstsReceived””
}
],
“type”: “search_phase_execution_exception”,
“reason”: “all shards failed”,
“phase”: “query”,
“grouped”: true,
“failed_shards”: [
{
“shard”: 0,
“index”: “joeldncc-2017.06.15”,
“node”: “qyHnVcWrRXycI0-twro3Kg”,
“reason”: {
“type”: “number_format_exception”,
“reason”: “For input string: “NumberofAlohaBurstsReceived””
}
}
]
}

But please note that in the template for elasticsearch I have specified that it will receive an “integer” from logstash.

Looks like something is wrong with your Elasticsearch index mapping for logstash. What does the mapping look like?

Get indices:

curl -s localhost:9200/_cat/indices

Get mapping:

curl -s localhost:9200/<name of your index>/_mapping

hii guys, I want to choose terms and group by are the value of variables. is there any way to do it? Many thanks

What do you mean by using a group by for template variables? Can you give an example?

Docs for template variables and ES are here in case you haven’t seen them.

hi Danielle, thank for your reply, here it is the picture, my main idea here we parameter the value in terms, field, group by, then by, …
so we have dynamic reports