tell me the method of scrolling by using the scrolling api elasticsearch?

The scroll_id value changes in every response. So the next search call needs to use the new scroll id from the previous search response.

You started correctly with

POST <index-name>/_search?scroll=2m
{
  "query": {"match_all": {}}
}

In the response you get, a field called _scroll_id contains the next scroll id to use for the next call (like a cursor), let’s call it scroll_id_1:

GET /_search/scroll
{
  "scroll_id" : "<scroll_id_1>",
  "scroll": "2m"
}

In that next response, you get a new _scroll_id value (let’s call it scroll_id_2) that you need to use it for the next call:

GET /_search/scroll
{
  "scroll_id" : "<scroll_id_2>",
  "scroll": "2m"
}

And you keep doing it until you get an empty result set, at which point you can clear the search context

DELETE /_search/scroll
{
  "scroll_id" : "<scroll_id_n>"
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top