kibanaopensearchscriptedfield

How to sum values ​within a list using the scripted field in Kibana


I'm trying to add these values ​​of the "gapsLength" result but I still haven't had success, can anyone help

the image below shows the list I'm talking about

Gap Average result

I tried something like this

int sum = 0;
for (int number : doc["gap average.gapsLength"]) {
    sum += number;
}
return sum;

Solution

  • Looks like your code is almost there, it may be lacking just some painless syntax improvements. Example:

    for (int number in doc['gap average.gapsLength']) {
       ...
    }