Home > Software engineering >  how to apply pagination in the range query to get full records?
how to apply pagination in the range query to get full records?

Time:09-30

I am trying to apply pagination to my range query to get full records between the given date range.

Below is the query i tried using

Query:

   {
        "query": 
        {
            "range": 
            {
                "sys_created_on": 
                    {
                        "gte":"2022-01-01 01:00:00", 
                        "lte":"2022-03-10 01:00:00"
                    }
            }
        },
        "sort": [
            {"sys_created_on": "asc","u_user_updated": "asc"}
            ]
    }

payload:

    {
        "took": 62,
        "timed_out": false,
        "_shards": {
            "total": 8,
            "successful": 8,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 10000,
                "relation": "gte"
            },
            "max_score": null,
            "hits": [
                {
                    "_type": "_doc",
                    "_id": "61c158191bbc89905ad62064604bcb39",
                    "_score": null,
                    "_source": {
               "key1":"val1",
                "key2":"val2",
                --------
                --------
                "keyn":"valn",
}
                }
        }

In the above query "sys_created_on" and "u_user_updated" are the fields available in my payload response. As said in this documentation, [elastic_search_search_query], I am not getting the payload with "sort" as key. So that I can use the search_after

CodePudding user response:

Try changing

"sort": [
        {"sys_created_on": "asc","u_user_updated": "asc"}
        ]

for

"sort": [
        {"sys_created_on": "asc"}, {"u_user_updated": "asc"}
        ]
  • Related