Division between two sum fields

Hi,
I need help to calculate the division between two sum. How can I do?

something like

"aggs" : {
"sum_1" : { "sum" : { "field" : "flag_barisolve" } },
"sum_2" : { "sum" : { "field" : "flag_anagrafe" } }
"division" : {
...
"script" : {
"lang": "painless",
"inline": "sum_1 / sum_2"
}
}

Thanks

Take a look at pipeline aggregations. These are aggregations that work on the result of other aggregations. In your example, you could use a bucket_script pipeline aggregation:

"aggs": {
  "sum_1": {
    "sum": {
      "field": "flag_barisolve"
    }
  },
  "sum_2": {
    "sum": {
      "field": "flag_anagrafe"
    }
  },
  "division": {
    "bucket_script": {
      "buckets_path": {
        "my_var1": "sum_1",
        "my_var2": "sum_2"
      },
      "script": "params.my_var1 / params.my_var2"
    }
  }
}

This does not work for root-level aggregations. So, the sum_1, sum_2 and division aggregations must be child aggregations inside a multi-bucket aggregation.

Hi abdon,
thanks a lot for your support.
With the Sense client query is correct.
How to display the result in a visualize of Kibana (ex. data table)?

It's off topic?

Thanks

Take a look at Timelion. It will allow you to do things like this in Kibana visualizations.

It's possible visulize output, root aggregations and division, with data table or bar chart?
Thanks

All of that should be possible, with the exception of the data table. I don't think Timelion supports data tables.

Take a look at the built-in tutorial to see what it can do. Timelion's syntax is very different from the regular aggregations, so there is a bit of a learning curve.

I want use Kibana's visualize like data table, vertical bar chart, pie chart, ecc...

It's possible with the pipeline aggregations like above query?

Thanks

No, that's currently not supported. The only way to do something similar to that is with Timelion.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.