Divide Sums with conditions an d group by

I have documents that looks like

  "_source": {
    "Number_2": 64,
    "Name_A": "RANDOM_A",
    "Number_1": 4,
    "Name_B": "RANDOM_B"

I would like to show a ratio calculation of the following

x = sum(number_1) group by name_a
y = sum(number_2) group by name_a
calculate x/y

so each value will be summed once, as unique. Then show it on a graph or a metric.
Eventually, use this metric in a ML job.

Number_1 values = 4,4,8,8,16,32,32,32,32
Number_2 values = 64,64

(4+4+8+8+16+32+32+32+32)/(64+64) = 168/128 = 0.76

How is that possible?
I did a few tries and errors, but they all fail.


Hi @AClerk,
I recommend using a Filter Ratio in a TSVB visualization with a Filter Ratio aggregation. There's a great description of how to set this up in this discuss Q&A on computing and displaying a ratio. It's a slightly older post, and depending on the version of Kibana that you're running, you can also reference the guide in the docs.

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