Graph a ratio between two counts


I would like to graph a ratio between two counts on the same index.

For example, if we take the books dataset, count the ratio of American book out of all the expensive books (more than 10$)
count(books where country=US and price > 10$) / count ( books where price > 10$)

I want to be able to graph the evolution of this ratio aggregated per day of publication or any kind of bucketing (per country, per geohash, ...).

Do you have any idea on how to do that ? Considering that I can afford changing the data structure.

Thank you.

You mean this issue?

1 Like

Yes indeed, it seems to be related to this limitation.
Thank you.

Btw, Timelion plugin for Kibana was just released, which makes doing ratios in Elasticsearch of two series trivial:

Thank you Tanya for pointing out Timelion.
It seems very promising.

1 Like

Hi Tanya,

Is TimeLion able to calculate a CTR , ie count(occurrence of text field A) / count(occurrence of text field B) * 100?

The video shows something the creator made but it doesn't describe the syntax of the query language and its vocabulary.

Many thanks.

Documentation seems very sparse for timelion. But you should be able to do that.


With TimeLion we have the ratio over the Time, is it possible to have the ratio per term of a field?