# How to combine aggregations

**URL:** <https://discuss.elastic.co/t/how-to-combine-aggregations/21650>\
**Category:** Elasticsearch\
**Created:** [January 14, 2015, 9:43pm UTC](https://discuss.elastic.co/t/how-to-combine-aggregations/21650 "2015-01-14T21:43:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yan\_Georget](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@Yan\_Georget](https://discuss.elastic.co/u/Yan_Georget)\
**Post date:** [January 14, 2015, 9:43pm UTC](https://discuss.elastic.co/t/how-to-combine-aggregations/21650/1 "2015-01-14T21:43:50Z")

</div>

Hello,

Let's imagine I am logging displays and clicks, say by cities.  
I can aggregate those by countries and I can also compute grand totals.

Now I would like to compute click rates (clicks/displays) by cities,  
countries and I would also like to get a global click rate.  
How can I do this?

It seems that I could use a scripted metric (I have not tried yet) but I  
would also like to expose these rates in Kibana.

It is possible?

Thanks in advance,  
Yan Georget

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [January 15, 2015, 9:52am UTC](https://discuss.elastic.co/t/how-to-combine-aggregations/21650/2 "2015-01-15T09:52:14Z")

</div>

I believe you could run a terms aggregation on the city field, and under  
this terms aggregation put two sum aggregations, one for clicks and one for  
displays. And finally you could derive the click rate from the sum of  
clicks and displays on client side? If you are starting playing with  
aggregations, I would recommend reading this blog post by Zachary Tong:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wed, Jan 14, 2015 at 10:43 PM, Yan Georget [yan@ogury.co](mailto:yan@ogury.co) wrote:

> Hello,
> 
> Let's imagine I am logging displays and clicks, say by cities.  
> I can aggregate those by countries and I can also compute grand totals.
> 
> Now I would like to compute click rates (clicks/displays) by cities,  
> countries and I would also like to get a global click rate.  
> How can I do this?
> 
> It seems that I could use a scripted metric (I have not tried yet) but I  
> would also like to expose these rates in Kibana.
> 
> It is possible?
> 
> Thanks in advance,  
> Yan Georget
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c5356c3e-9322-4708-9c20-eed270ee57d9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j69AGX4bH4eL%3DxP6a84oT-64Op1FqGha5iMJJZ\_hzVAnA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j69AGX4bH4eL%3DxP6a84oT-64Op1FqGha5iMJJZ_hzVAnA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:38am UTC](https://discuss.elastic.co/t/how-to-combine-aggregations/21650/3 "2017-07-06T00:38:45Z")

</div>

Closed on July 6, 2017, 12:38am UTC


