|
4 | 4 | The Scroll API can be used to retrieve a large number of results from |
5 | 5 | a search request. |
6 | 6 |
|
7 | | -In order to use scrolling, the initial search request must define |
8 | | -a value for the scroll parameter: |
| 7 | +In order to use scrolling, several steps need to be executed in a given order: |
9 | 8 |
|
10 | | -["source","java",subs="attributes,callouts,macros"] |
11 | | --------------------------------------------------- |
12 | | -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-request] |
13 | | --------------------------------------------------- |
14 | | -<1> Create a new `SearchRequest`. See <<java-rest-high-search>> |
15 | | -for more information on how to build `SearchRequest`. |
16 | | -<2> Set the `scroll` parameter as a `TimeValue` corresponding to one minute |
| 9 | +* At first, an initial search request with a non-null `scroll` parameter must |
| 10 | +be executed. When processing this `SearchRequest`, Elasticsearch detects the |
| 11 | +presence of the `scroll` parameter and keeps the search context alive during |
| 12 | +the time defined by the parameter. Elasticsearch generates a scroll identifier |
| 13 | +associated to this search context and returns it with the first batch of search |
| 14 | +results in a `SearchResponse`. |
17 | 15 |
|
18 | | -When executing the `SearchRequest`, Elasticsearch detects the presence |
19 | | -of the `scroll` parameter and keeps the search context alive during the time |
20 | | -defined by the parameter. |
| 16 | +* As a second step, the initial scroll parameter and the new scroll identifier |
| 17 | +are set in a `SearchScrollRequest`. This request is executed using the Search |
| 18 | +Scroll API and Elasticsearch returns the second batch of results with a new |
| 19 | + scroll identifier. This new scroll id can then be used in another `SearchScrollRequest` |
| 20 | + to retrieve the next batch of results. This process can be repeated over and |
| 21 | + over until no more results are returned. |
21 | 22 |
|
22 | | -It then returns a `SearchResponse` that includes a scroll id: |
| 23 | +* Finally, the last scroll identifier can be deleted using the <<java-rest-high-clear-scroll>> |
| 24 | +in order to release the search context. |
23 | 25 |
|
24 | | -["source","java",subs="attributes,callouts,macros"] |
25 | | --------------------------------------------------- |
26 | | -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-response-scroll-id] |
27 | | --------------------------------------------------- |
28 | | -<1> Execute the `SearchRequest` |
29 | | -<2> Retrieve the search hits |
30 | | -<3> Retrieve the scroll id |
| 26 | +[[java-rest-high-search-scroll-example]] |
| 27 | +==== Example of Execution |
31 | 28 |
|
32 | | -This scroll id should be passed to a `SearchScrollRequest` which can be executed |
33 | | -using the Search Scroll API in order to retrieve the next batch of results. Then |
34 | | -the same process can be repeated over and over until no more results are returned. |
35 | | -The initial search request as well as all subsequent scroll requests return a |
36 | | -scroll id that can be passed to the next scroll request until results are exhausted. |
| 29 | +Here is an example of a scrolled search: |
37 | 30 |
|
38 | 31 | ["source","java",subs="attributes,callouts,macros"] |
39 | 32 | -------------------------------------------------- |
40 | | -include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-execute] |
| 33 | +include-tagged::{doc-tests}/SearchDocumentationIT.java[search-scroll-example] |
41 | 34 | -------------------------------------------------- |
42 | | -<1> Create a new `SearchScrollRequest` |
43 | | -<2> Set the `scroll` parameter again to tell Elasticsearch to keep the search context |
| 35 | +<1> Define a scroll parameter as a `TimeValue` corresponding to one minute |
| 36 | +<2> Create a new `SearchRequest`. See <<java-rest-high-search>> |
| 37 | +for more information on how to build `SearchRequest`. |
| 38 | +<3> Set the `scroll` parameter to the `SearchRequest` |
| 39 | +<4> Execute the `SearchRequest` |
| 40 | +<5> Retrieve the first scroll id |
| 41 | +<6> Retrieve the first batch of search hits |
| 42 | +<7> Iterate until there are no more search hits to process |
| 43 | +<8> Create a new `SearchScrollRequest` |
| 44 | +<9> Set the `scroll` parameter again to tell Elasticsearch to keep the search context |
44 | 45 | alive for another minute |
45 | | -<3> Set the scroll id |
46 | | -<4> Execute the `SearchScrollRequest` |
47 | | -<5> Retrieve the next scroll id to use in upcoming requests |
48 | | -<6> Retrieve the next batch of search hits |
49 | | -<7> The request returned search hits that can be processed |
50 | | -<8> There are no more search hits to process, the scrolling is terminated |
51 | | - |
52 | | -Finally, the scroll id can be deleted using the <<java-rest-high-clear-scroll>>. |
| 46 | +<10> Set the scroll id |
| 47 | +<11> Execute the `SearchScrollRequest` using the Search Scroll API |
| 48 | +<12> Retrieve the next scroll id to use in upcoming requests |
| 49 | +<13> Retrieve the next batch of search hits |
| 50 | +<14> Clear the scroll id using the <<java-rest-high-clear-scroll>>. |
53 | 51 |
|
54 | 52 | ==== Optional arguments |
55 | 53 | The following argument can optionally be provided: |
|
0 commit comments