# Aggregate through pages

**URL:** <https://discuss.elastic.co/t/aggregate-through-pages/223491>\
**Category:** Elasticsearch\
**Created:** [March 13, 2020, 11:01am UTC](https://discuss.elastic.co/t/aggregate-through-pages/223491 "2020-03-13T11:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![babayotakun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babayotakun/32/64403_2.png) [@babayotakun](https://discuss.elastic.co/u/babayotakun)\
**Post date:** [March 13, 2020, 11:01am UTC](https://discuss.elastic.co/t/aggregate-through-pages/223491/1 "2020-03-13T11:01:31Z")

</div>

We have a query which returns a large number of results, sorted alphabetically and we're using a pagination to iterate through these pages.  
I wonder: can we use aggregations to get the page, containing the element with the largest score?

Just for example, we have 10 results of query (match: "Foo") in 4 pages, sorted alphabetically:

1. A Foo | (score 1)
2. B Foo | (score 1)
3. C Foo | (score 1)

* * *

1. D Foo | (score 1)
2. E Foo | (score 1)
3. Foo | (score 2)

* * *

1. G Foo | (score 1)
2. H Foo | (score 1)
3. I Foo | (score 1)

* * *

1. Foo | (score 1)

How can we get something like that?

top result:  
| Foo  
top page:  
| Number: 2  
| Content:  
| 4. D Foo | (score 1)  
| 5. E Foo | (score 1)  
| 6. Foo

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2020, 4:30pm UTC](https://discuss.elastic.co/t/aggregate-through-pages/223491/2 "2020-03-13T16:30:32Z")

</div>

I am not sure I follow that request. If the `from` and `size` parameters are not doing what you expect them to do, then explain a bit further. See [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/search-request-body.html#request-body-search-from-size](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/search-request-body.html#request-body-search-from-size)

---

<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:** [April 10, 2020, 4:30pm UTC](https://discuss.elastic.co/t/aggregate-through-pages/223491/3 "2020-04-10T16:30:32Z")

</div>

Closed on April 10, 2020, 4:30pm UTC

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