# Paginating through results in a query that doesnt use sort

**URL:** <https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160>\
**Category:** Elasticsearch\
**Created:** [October 7, 2021, 8:32pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160 "2021-10-07T20:32:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Mackey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_mackey/32/83901_2.png) [@John\_Mackey](https://discuss.elastic.co/u/John_Mackey)\
**Post date:** [October 7, 2021, 8:32pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160/1 "2021-10-07T20:32:24Z")

</div>

We have the below query that returns 15K results.

How do we paginate through all the results

From the examples for search\_after , it can be used only if we are sorting by a unique field in the query . We do not intend to use any sort in the query

```auto
{
    "_source": [
        "Id",
        "EntityName"
    ],
    "size": 100,
    "query": {
        "bool": {
            "should": [
                {
                    "multi_match": {
                        "_name": "Exact Match",
                        "type": "phrase",
                        "query": "Alibaba Group Holding Limited",
                        "fields": [
                            "EntityName.keyword"
                        ],
                        "boost": 4
                    }
                },
                {
                    "multi_match": {
                        "_name": "Partial Match",
                        "type": "phrase",
                        "query": "Alibaba Group",
                        "fields": [
                            "EntityName"
                        ],
                        "boost": 2
                    }
                },
                {
                    "multi_match": {
                        "_name": "Partial Match variation",
                        "type": "phrase",
                        "query": "Alibabas Group",
                        "fields": [
                            "EntityName"
                        ],
                        "boost": 2
                    }
                }
            ],
            "minimum_should_match": 1
        }
    }
}

```

Thanks,  
Sandeep

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 7, 2021, 9:09pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160/2 "2021-10-07T21:09:04Z")

</div>

Welcome !

You can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

---

<div class="post-metadata">

**Author:** ![John\_Mackey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_mackey/32/83901_2.png) [@John\_Mackey](https://discuss.elastic.co/u/John_Mackey)\
**Post date:** [October 8, 2021, 12:37pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160/3 "2021-10-08T12:37:53Z")

</div>

Hi David,  
Can I use search\_after with the query that I have pasted ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 8, 2021, 1:46pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160/4 "2021-10-08T13:46:51Z")

</div>

I'm not sure.

I believe that if you are using `_pit` to not take into account any change to the index after the first run, then you could may be use the score? By default, everything is sorted on the `_score`.

---

<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 5, 2021, 1:47pm UTC](https://discuss.elastic.co/t/paginating-through-results-in-a-query-that-doesnt-use-sort/286160/5 "2021-11-05T13:47:09Z")

</div>

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