# Top Hits Aggregation Maximum Size?

**URL:** <https://discuss.elastic.co/t/top-hits-aggregation-maximum-size/131350>\
**Category:** Elasticsearch\
**Created:** [May 10, 2018, 7:52pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-maximum-size/131350 "2018-05-10T19:52:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevybear](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevybear/32/25872_2.png) [@kevybear](https://discuss.elastic.co/u/kevybear)\
**Post date:** [May 10, 2018, 7:52pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-maximum-size/131350/1 "2018-05-10T19:52:07Z")

</div>

Is there a maximum size to the number of documents returned by top hits sub aggregation?

> [SearchRequest{searchType=QUERY\_THEN\_FETCH, indices=[container, container], indicesOptions=IndicesOptions[id=38, ignore\_unavailable=false, allow\_no\_indices=true, expand\_wildcards\_open=true, expand\_wildcards\_closed=false, allow\_aliases\_to\_multiple\_indices=true, forbid\_closed\_indices=true, ignore\_aliases=false], types=, preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=128, source={"size":0,"query":{"bool":{"filter":[{"term":{"isDeleted":{"value":false,"boost":1.0}}}],"adjust\_pure\_negative":true,"boost":1.0}},"aggregations":{"stackingFilter":{"terms":{"field":"stackingFilter","size":100000,"min\_doc\_count":1,"shard\_min\_doc\_count":0,"show\_term\_doc\_count\_error":false,"order":[{"\_count":"desc"},{"\_key":"asc"}]},"aggregations":{"top":{"top\_hits":{"from":0,"size":101,"version":false,"explain":false}}}}}}}]

Because of the "size":101 parameter it throws the following exception:

> Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [[https://search-analytics-upgrade-bsm7mewvlxsjiw26pxvk43snfu.us-east-1.es.amazonaws.com](https://search-analytics-upgrade-bsm7mewvlxsjiw26pxvk43snfu.us-east-1.es.amazonaws.com)], URI [/container,container/\_search?routing=DSF2&typed\_keys=true&ignore\_unavailable=false&expand\_wildcards=open&allow\_no\_indices=true&search\_type=query\_then\_fetch&batched\_reduce\_size=512], status line [HTTP/1.1 400 Bad Request]

When i change the size to \<=100 it works fine. This is ES 6.2

---

<div class="post-metadata">

**Author:** ![kevybear](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevybear/32/25872_2.png) [@kevybear](https://discuss.elastic.co/u/kevybear)\
**Post date:** [May 10, 2018, 8:07pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-maximum-size/131350/2 "2018-05-10T20:07:48Z")

</div>

Also, would it be more efficient to do terms aggreagion with top hits subaggregation from ES server side, or would it be more efficient to do searchScroll then do the group by on the client side? Assuming around 100k documents per bucket?

---

<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:** [June 7, 2018, 8:07pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-maximum-size/131350/3 "2018-06-07T20:07:54Z")

</div>

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