# Multiple Aggregation Query

**URL:** <https://discuss.elastic.co/t/multiple-aggregation-query/195201>\
**Category:** Elasticsearch\
**Created:** [August 14, 2019, 12:27pm UTC](https://discuss.elastic.co/t/multiple-aggregation-query/195201 "2019-08-14T12:27:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeboy](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@codeboy](https://discuss.elastic.co/u/codeboy)\
**Post date:** [August 14, 2019, 12:27pm UTC](https://discuss.elastic.co/t/multiple-aggregation-query/195201/1 "2019-08-14T12:27:52Z")

</div>

We are running a query that looks for the equivalent "select distinct f1,f2,f3 from myindex". The resulting query is implemented with nested aggregations. Since we are returning a LOT of data, the performance with 2 tiers of nested aggregation is good, but becomes unacceptable with 3 tiers.

Is there a better way to bring additional fields without additional aggregation tiers? We would prefer something like "select f1,f2,first(f3),first(f4),first(f5) from myindex group by f1,f2" So that the aggregation only 2 goes tiers.

I hope I have explained this problem clearly.

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [August 15, 2019, 3:32am UTC](https://discuss.elastic.co/t/multiple-aggregation-query/195201/2 "2019-08-15T03:32:30Z")

</div>

I'm not sure whether [Top Hits Aggs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html) can help u.

---

<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:** [September 12, 2019, 3:32am UTC](https://discuss.elastic.co/t/multiple-aggregation-query/195201/3 "2019-09-12T03:32:41Z")

</div>

Closed on September 12, 2019, 3:32am UTC

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