Using ElaasticSearch script in the Grafana

Hi, I’m going to use this ElasticSearch query in the Grafana:

But the result in Grafana is something like this:

How can I remove the field part completely?

What is the query in Grafana Query?

There is the query:

{“size”:0,“query”:{“bool”:{“filter”:[{“range”:{“from-date”:{“gte”:1575289128751,“lte”:1606911528752,“format”:“epoch_millis”}}},{“query_string”:{“analyze_wildcard”:true,“query”:"*"}}]}},“aggs”:{“2”:{“date_histogram”:{“interval”:“1d”,“field”:“from-date”,“min_doc_count”:0,“extended_bounds”:{“min”:1575289128751,“max”:1606911528752},“format”:“epoch_millis”},“aggs”:{“3”:{“sum”:{“field”:“load-value”,“script”:{“inline”:“Double.parseDouble(_value)”}}}}}}}

Which is created by this configuration:

What you want to achieve with that script?
Because the script field in the metric, just do aritmatic calculation from the metric value, such as, _value * 10

I want to parse a value with keyword type to double.

Need more information about the data that you stored in the elasticsearch. You can paste here with removing sensitive data, also what format to display do you need with the value inside the index.

There is a sample data:
{
“from-date”: “2020-05-10T23:00:00+02:00”,
“until-date”: “2020-05-10T23:15:00+02:00”,
“load-value”: 37500,
}

There is the mapping:
“from-date”: {
“type”: “date”
},
“until-date”: {
“type”: “date”
},
“load-value”: {
“type”: “keyword”
}

I want to create sum aggregation over load-value, but the load-value type is keyword. I have two options:
1- changing the load-value type that causes a reindex
2- casting the load-value to double dynamically

I tried the second one in the ElasticSearch, but in Grafana I could not prepare the correct query.

I suggest to change the type into integer, then you will simple enough to aggregate the value.
If there using logstash as ingestion tools, just modify the filter using mutate copy_field, and convert from string to integer.
The other way around using reindex with pipeline to change the field type.

Thank you for your responses.

I manipulated the native ElasticSearch data source plugin. Now if the field does not have value and the script has, It will only use the script in an inline tag.

The result is something like this:

“aggs”:{“3”:{“sum”:{“script”:{“inline”:“Double.parseDouble(doc[‘load-value’].value)”}}}}