Elasticsearch + Grafana Template issue

Hello,

I am using Elasticsearch as a datasounce in Grafana. I want to create a template, that will display all the options, for a specific field.

For example, I have the following fields: status, code2, check, category.
I want to create a template with the field called code2, so i can select from a dropdown the options under code2.

In Templates, I created the following query to select code2:
{ “find”: “fields”, “field”: “code2”, “type”:“string”}

Instead of selecting the particular field, this returns all fields.
In preview values I see the following:
status, code2, check, category

What is the correct query to select only code2?

Actually, i can see the field I want to select is inside _source tag, as below:
{
"_index" : “private”,
"_type" : “logs”,
"_id" : “xyz”,
"_source" : {
“value1” : “xyzxyz”,
“value2” : null,
“code2” : “xxx”,
}
}

How do I select code2 from the _source tag for the query?

Looks at the docs, you want find terms not fields

Thanks, I see I can see i can use terms instead. When changing my Json, it seems it works well for fields outside of source like index, type, id, they get returned. It seems I cannot get the fields inside _source though. When I specify code2, it doesn’t return anything. Any suggestion?

Field inside source are not indexed and you can only execute terms queries on indexed properties

… or against the corresponding “keyword” fields (e.g., { “find”: “terms”, “field”: “code2.keyword” })

I believe this applies if a terms query for “code2” causes an error like this:

Fielddata is disabled on text fields by default. Set fielddata=true … Alternatively use a keyword field instead.

1 Like