Executing a scan query
Every time a query is executed, the results are calculated and returned to the user. In ElasticSearch, there is no deterministic order for the records; pagination on a big block of values can result in inconsistency between the results due to documents being added and deleted, and also between documents with the same score. The scan query tries to resolve these kinds of problems by providing a special cursor that allows you to uniquely iterate all the documents. It's often used to back up documents or reindex them.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_05/populate_query.sh
) available in the code bundle for this book.
How to do it...
In order to execute a scan query, perform the following steps:
From the command line, execute a search of the type scan:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&search_type=scan&scroll=10m&size=50' -d '{"query":{"match_all":{}}}'
If...