# Top Hits Aggregation: Paging

**URL:** <https://discuss.elastic.co/t/top-hits-aggregation-paging/27418>\
**Category:** Elasticsearch\
**Created:** [August 14, 2015, 4:19pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-paging/27418 "2015-08-14T16:19:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [August 14, 2015, 4:19pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-paging/27418/1 "2015-08-14T16:19:48Z")

</div>

Is it possible apply paging on the Top Hits Aggregation?

I quote from the reference documentation:

> The top hits returned in each bucket are the result of running a light mini-query based on the original main query. The mini-query supports the usual features that you would expect from search such as highlighting and pagination.

> **[Field Collapsing | Elasticsearch: The Definitive Guide \[2.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/top-hits.html)**

Using the Java client, I have found a setFrom and setSize, but this probably only applies to the Top Hits and not the number of buckets found. We can set the _size_ of an aggregation, but not the _from_.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 14, 2015, 9:01pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-paging/27418/2 "2015-08-14T21:01:29Z")

</div>

The `top_hits` agg does support `from` and `size`, but that is paginate the search hits in a bucket and not to paginate the buckets that result from the terms or other bucket aggs.

There is an issue open in GH fit this feature request: [https://github.com/elastic/elasticsearch/issues/4915](https://github.com/elastic/elasticsearch/issues/4915)

But it is tricky to implement efficiently, so it is unknown if and when it will be available in ES. The best way to emulate the support for paginating relatively efficiently is by using the client side work around using `include` and `exclude` described in this issue.

---

<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:** [July 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/top-hits-aggregation-paging/27418/3 "2017-07-05T23:55:43Z")

</div>


