PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 25, 2022

[FIXED] how to apply pagination in the range query to get full records?

 October 25, 2022     elasticsearch, elasticsearch-5     No comments   

Issue

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


Solution

Try changing

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

for

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


Answered By - Trickster Júnior
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing