Paginating through results in a query that doesnt use sort

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

{
    "_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

Welcome !

You can use:

  • the size and from parameters 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 feature to do deep pagination.
  • the Scroll API if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

Hi David,
Can I use search_after with the query that I have pasted ?

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.

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