# Get top hits aggregation without aggregating on all values

**URL:** <https://discuss.elastic.co/t/get-top-hits-aggregation-without-aggregating-on-all-values/151790>\
**Category:** Elasticsearch\
**Created:** [October 10, 2018, 8:23am UTC](https://discuss.elastic.co/t/get-top-hits-aggregation-without-aggregating-on-all-values/151790 "2018-10-10T08:23:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [October 10, 2018, 8:23am UTC](https://discuss.elastic.co/t/get-top-hits-aggregation-without-aggregating-on-all-values/151790/1 "2018-10-10T08:23:12Z")

</div>

Hey,

Based on the [documentation](https://www.elastic.co/guide/en/elasticsearch//reference/6.2/search-aggregations-metrics-top-hits-aggregation.html) top aggregations can be used as a sub aggregator.

Maybe I can achieve it in a different way but my use case is:  
I have the following structure:

```
{
    name: "x"
}

```

I basically need to get the top 10 document based on the name field.  
The problem is that I have 100M documents, and possible 100K values for the name field.  
From what I understand, this is not a good use case for ES, because running an aggregation with more then tens of thousands buckets will not have good performance, and will take a lot in terms of resources from the cluster.

To sum it up. I just need the topX documents based on a field with many possible values.

Is there a "good" way to achieve this?  
Is my assumption regards the number of buckets is wrong?

Thanks!!

---

<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:** [November 7, 2018, 8:23am UTC](https://discuss.elastic.co/t/get-top-hits-aggregation-without-aggregating-on-all-values/151790/2 "2018-11-07T08:23:13Z")

</div>

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