Using the search_after functionality
Elasticsearch standard pagination using from
and size
performs very poorly on large datasets because for every query you need to compute and discard all the results before the from value. The scrolling doesn't have this problem, but it consumes a lot, due to memory search contexts, so it cannot be used for frequent user queries.
To bypass these problems, Elasticsearch 5.x provides the search_after
functionality that provides a fast skipping for scrolling results.
Getting ready
You will need an up-and-running Elasticsearch installation as used in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via a command line, you need to install curl
for your operating system.
To correctly execute the following commands, you will need an index populated with the chapter_05/populate_query.sh
script available in the online code.
How to do it...
In order to execute a scrolling query, we will perform the following steps...