# How to merge results of two aggregations

**URL:** https://discuss.elastic.co/t/how-to-merge-results-of-two-aggregations/43351
**Category:** Elasticsearch
**Created:** [March 3, 2016, 8:48am UTC](https://discuss.elastic.co/t/how-to-merge-results-of-two-aggregations/43351 "2016-03-03T08:48:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Aravindh\_S](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@Aravindh\_S](https://discuss.elastic.co/u/Aravindh_S)
#### Post date: [March 3, 2016, 8:48am UTC](https://discuss.elastic.co/t/how-to-merge-results-of-two-aggregations/43351/1 "2016-03-03T08:48:00Z")

</div>

Hi, I have two terms aggregations. Both return an id and a doc\_count for each of the ids. How can I merge the result of these two. I would like to do an union as well as intersection of both the results.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [March 3, 2016, 9:24am UTC](https://discuss.elastic.co/t/how-to-merge-results-of-two-aggregations/43351/2 "2016-03-03T09:24:49Z")

</div>

Take a look at pipeline aggs [https://www.elastic.co/guide/en/elasticsearch/reference/2.2/search-aggregations-pipeline.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/search-aggregations-pipeline.html)

If that doesn't do it then you need to do it in code.

---

<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 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/how-to-merge-results-of-two-aggregations/43351/3 "2017-07-05T23:11:42Z")

</div>


