# Aggregation on multiple fields

**URL:** <https://discuss.elastic.co/t/aggregation-on-multiple-fields/157793>\
**Category:** Elasticsearch\
**Created:** [November 22, 2018, 2:39am UTC](https://discuss.elastic.co/t/aggregation-on-multiple-fields/157793 "2018-11-22T02:39:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mctsdmr](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@mctsdmr](https://discuss.elastic.co/u/mctsdmr)\
**Post date:** [November 22, 2018, 2:39am UTC](https://discuss.elastic.co/t/aggregation-on-multiple-fields/157793/1 "2018-11-22T02:39:54Z")

</div>

Hello folks!

I need a query in which I can aggregate on multiple fields -4 fields to be more specific- and as far as I understand, the only way to create such a query is using nested aggregations. But when that's the case, I have two problems:  
1- I could not find a way to limit the total number of inner-most buckets  
2- I could not find a way to order by the inner-most buckets so that I can retrieve the top N of them according to their values.

I'd be glad if anyone can help me get rid of this mess.

Thank you all in advance!

---

<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:** [December 20, 2018, 2:39am UTC](https://discuss.elastic.co/t/aggregation-on-multiple-fields/157793/2 "2018-12-20T02:39:59Z")

</div>

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