Do calculations in kibana visualization JSON input

Hi,

I´m trying to do script calculation using the result of a metric and a field in JSON input. I change the elasticsearch.yml configuration to allowed scripting adding:

script.engine.groovy.inline.search: true
script.groovy.sandbox.enabled: true
script.inline: on
script.indexed: on
script.search: true
script.engine.groovy.inline.aggs: true

_value is the result of a sum in kibana metrics visualization and in the same metric putting:

{
"script": " _value / 9"
}

in the JSON input, kibana gives the correct result. But if the script needs the value of a field like:

{
"script": "_value / doc['some-field'].value "
}

kibana don´t show the correct result or don´t give any result.

Some one can help me with this? Thanks!

1 Like

By default Kibana defaults to the Lucene expressions scripting language, so you need to include the "lang" : "groovy" parameter in your script. See example here Calling groovy script from Kibana

Thank you for your help! I try your solution, but for the division operator kibana don´t give any result.

kibana JSON input:

{ "script": "_value + doc['HTTP_Request'].value ", "lang" : "groovy" }

{ "script": "_value - doc['HTTP_Request'].value ", "lang" : "groovy" }

{ "script": "_value + 9", "lang" : "groovy" }

For sum, subtraction and divisions with a specific number it's ok.

{ "script": "_value / doc['HTTP_Request'].value ", "lang" : "groovy" }

But for this script kibana don´t show any result.

Thanks

Basically I want to do some calculations like:

(∑MISS / ∑HTTP requests – ∑Manifests requests – ∑m3u8 requests) in Δt * 100%
But I don´t know if I can do this kind of formulas in Kibana or Elasticsearch.

Thanks.

2 Likes