Executing a scroll search
Pagination with a standard query works very well if you are matching documents with documents that do not change too often; otherwise, performing pagination with live data returns unpredictable results. To bypass this problem, Elasticsearch provides an extra parameter in the query: scroll
.
Getting ready
You need an up-and-running Elasticsearch installation, which you can get as described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
A Maven tool, or an IDE that natively supports it for Java programming, such as Visual Studio Code, Eclipse, or IntelliJ IDEA, must be installed.
The code for this recipe is in the ch13/elasticsearch-java-client
directory and the referred class is ScrollQueryExample
.
How to do it...
The search is done as it was shown in the Execute a standard search recipe in Chapter 4, Exploring Search Capabilities. The main difference is the use of a scroll
timeout, which allows the resulting...