3

Using ES and AngularJS to make a small search app. I'm trying to understand how to implement the scan and scroll feature in ES to use for pagination.

The docs say to make a search request and then to include a 'search_type: scan' and 'scroll' parameters.

Do I just add those parameters to my current search request or do I need to make another search request and specify request as the scan and scroll search request?

1 Answer 1

2

As documentation explain you need to make the first call using

GET /old_index/_search?search_type=scan&scroll=1m 
{
    "query": { "match_all": {}},
    "size":  1000
}

The response to this request doesn’t include any hits (means content you search) but scroll id like following

{
    "_scroll_id" : "c2Nhbjs1OzMwNTYzMTkxNjpTSkM2S0cxVFJIeUk1NnZWbGFUV1FnOzMwNTYzMTkxNTpTSkM2S0cxVFJIeUk1NnZWbGFUV1FnOzMwNTYyMjEwNzp4OEkwZE54eVR0cXI4cHAzU2I5UmlBOzMwNTYzNTE0NjpQZEhCSUZXeFJZU3daaDJKZXZCRmh3OzMwNTY0OTg4OTphdEE1OTN2NFFsYVY5ZjJ4SUxuVFpROzE7dG90YWxfaGl0czoyOTIwOw==",
    "took" : 10,
    "timed_out" : false,
    "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
    },
    "hits" : {
        "total" : 2920,
        "max_score" : 0,
        "hits" : []
    }
} 

After this you can use normal call with the scroll_id GET /_search/scroll?scroll=1m&_scroll_idc2Nhbjs1OzMwNTYzMTkxNjpTSkM2S0cxVFJIeUk1NnZWbGFUV1FnOzMwNTYzMTkxNTpTSkM2S0cxVFJIeUk1NnZWbGFUV1FnOzMwNTYyMjEwNzp4OEkwZE54eVR0cXI4cHAzU2I5UmlBOzMwNTYzNTE0NjpQZEhCSUZXeFJZU3daaDJKZXZCRmh3OzMwNTY0OTg4OTphdEE1OTN2NFFsYVY5ZjJ4SUxuVFpROzE7dG90YWxfaGl0czoyOTIwOw==

_scroll_id can be in request or body

Sign up to request clarification or add additional context in comments.

3 Comments

so then on the initial request, you basically need to make 2 calls? First to scan&scroll and then another one to /_search/scroll?
Do I have to use scan and scroll or can I just use scroll?
To answer your first question, yes you need 2 calls, the first one just get scrolling_id. The second question: I think you need both because the costly part of deep pagination is the global sorting of results, but if we disable sorting, then we can return all documents quite cheaply. To do this, we use the scan search type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.