# Multiple aggregation in one request vs one aggregation per request performance

**URL:** <https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768>\
**Category:** Elasticsearch\
**Created:** [April 10, 2017, 8:19am UTC](https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768 "2017-04-10T08:19:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukolajko25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mukolajko25/32/17191_2.png) [@Mukolajko25](https://discuss.elastic.co/u/Mukolajko25)\
**Post date:** [April 10, 2017, 8:19am UTC](https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768/1 "2017-04-10T08:19:31Z")

</div>

Hi.

Im using aggregations to compute data analysis. I use query to filter results and then a lot of aggregations to get data i want.

For example

```
"query": {
 "filtered": {
  "filter": {
    "bool": {
      "must": [
        {
          "range": {
            "ticketing.summary.counts.orders": {
              "from": 3
            }
          }
        },
        {
          "type": {
            "value": "profile"
          }
        }
      ]
    }
  }
 }
},
aggs: {20-30 terms and nested aggregations here}

```

I have a question about performance. Is it correct approach to run all aggregations in one request. Or maybe i need to run 1-2 aggregation per request. So from my code snipped i will have to run 15 requests instead of 1.

Elastic search version is 2.4  
RAM : 5 GB for heap.  
Documents : 500K-700K

Thanks for help.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 10, 2017, 9:42am UTC](https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768/2 "2017-04-10T09:42:57Z")

</div>

Hey,

by splitting up, you could parallelize those aggregations across several requests. This however only makes sense, if there are no other requests doing search while you are running your aggregations.

As usual, the easiest way would be testing in your concrete use-case.

Also, you can use the shard request cache to cache responses, which might speed things up, if you have the same aggregations over and over again.

--Alex

---

<div class="post-metadata">

**Author:** ![Mukolajko25](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mukolajko25/32/17191_2.png) [@Mukolajko25](https://discuss.elastic.co/u/Mukolajko25)\
**Post date:** [April 10, 2017, 10:13am UTC](https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768/3 "2017-04-10T10:13:38Z")

</div>

Hi. Thanks for help.

I agree that testing is the easiest way to check. However I hoped that elastic search already have answers about this kind of issues. My query timing are OK, but i wonder maybe elastic search doing better with a lot of small aggregations, or it's doesn't care as they always will have same time to execute. Like time to execute 100 es request to make 1 aggregations at a time === time to execute 1 es request with 100 aggregations in it? What is better for es itself? Thank you.

---

<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:** [May 8, 2017, 10:22am UTC](https://discuss.elastic.co/t/multiple-aggregation-in-one-request-vs-one-aggregation-per-request-performance/81768/4 "2017-05-08T10:22:26Z")

</div>

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