scroll-api.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. [[scroll-api]]
  2. === Scroll API
  3. ++++
  4. <titleabbrev>Scroll</titleabbrev>
  5. ++++
  6. IMPORTANT: We no longer recommend using the scroll API for deep pagination. If
  7. you need to preserve the index state while paging through more than 10,000 hits,
  8. use the <<search-after,`search_after`>> parameter with a point in time (PIT).
  9. Retrieves the next batch of results for a <<scroll-search-results,scrolling
  10. search>>.
  11. ////
  12. [source,console]
  13. --------------------------------------------------
  14. GET /_search?scroll=1m
  15. {
  16. "size": 1,
  17. "query": {
  18. "match_all": {}
  19. }
  20. }
  21. --------------------------------------------------
  22. // TEST[setup:my_index]
  23. ////
  24. [source,console]
  25. --------------------------------------------------
  26. GET /_search/scroll
  27. {
  28. "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ=="
  29. }
  30. --------------------------------------------------
  31. // TEST[continued]
  32. // TEST[s/DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ==/$body._scroll_id/]
  33. [[scroll-api-request]]
  34. ==== {api-request-title}
  35. `GET /_search/scroll/<scroll_id>`
  36. deprecated:[7.0.0]
  37. `GET /_search/scroll`
  38. `POST /_search/scroll/<scroll_id>`
  39. deprecated:[7.0.0]
  40. `POST /_search/scroll`
  41. [[scroll-api-api-prereqs]]
  42. ==== {api-prereq-title}
  43. * If the {es} {security-features} are enabled, you must have the `read`
  44. <<privileges-list-indices,index privilege>> for the target data stream, index,
  45. or alias.
  46. [[scroll-api-desc]]
  47. ==== {api-description-title}
  48. You can use the scroll API to retrieve large sets of results from a single
  49. <<scroll-search-results,scrolling search>> request.
  50. The scroll API requires a scroll ID. To get a scroll ID, submit a
  51. <<search-search,search API>> request that includes an argument for the
  52. <<search-api-scroll-query-param,`scroll` query parameter>>. The `scroll`
  53. parameter indicates how long {es} should retain the
  54. <<scroll-search-context,search context>> for the request.
  55. The search response returns a scroll ID in the `_scroll_id` response body
  56. parameter. You can then use the scroll ID with the scroll API to retrieve the
  57. next batch of results for the request. If the {es} {security-features} are enabled,
  58. the access to the results of a specific scroll ID is restricted to
  59. <<can-access-resources-check,the user or API key that submitted the search>>.
  60. You can also use the scroll API to specify a new `scroll` parameter that extends
  61. or shortens the retention period for the search context.
  62. See <<scroll-search-results>>.
  63. IMPORTANT: Results from a scrolling search reflect the state of the index at the
  64. time of the initial search request. Subsequent indexing or document changes only
  65. affect later search and scroll requests.
  66. [[scroll-api-path-params]]
  67. ==== {api-path-parms-title}
  68. `<scroll_id>`::
  69. deprecated:[7.0.0]
  70. (Optional, string)
  71. Scroll ID of the search.
  72. +
  73. IMPORTANT: Scroll IDs can be long. We recommend only specifying scroll IDs using
  74. the <<scroll-api-scroll-id-param,`scroll_id` request body parameter>>.
  75. [[scroll-api-query-params]]
  76. ==== {api-query-parms-title}
  77. `scroll`::
  78. (Optional, <<time-units,time value>>)
  79. Period to retain the <<scroll-search-context,search context>> for scrolling. See
  80. <<scroll-search-results>>.
  81. +
  82. This value overrides the duration set by the original search API request's
  83. `scroll` parameter.
  84. +
  85. By default, this value cannot exceed `1d` (24 hours). You can change
  86. this limit using the `search.max_keep_alive` cluster-level setting.
  87. +
  88. IMPORTANT: You can also specify this value using the `scroll` request body
  89. parameter. If both parameters are specified, only the query parameter is used.
  90. `scroll_id`::
  91. deprecated:[7.0.0]
  92. (Optional, string)
  93. Scroll ID for the search.
  94. +
  95. IMPORTANT: Scroll IDs can be long. We recommend only specifying scroll IDs using
  96. the <<scroll-api-scroll-id-param,`scroll_id` request body parameter>>.
  97. `rest_total_hits_as_int`::
  98. (Optional, Boolean)
  99. If `true`, the API response's `hit.total` property is returned as an integer.
  100. If `false`, the API response's `hit.total` property is returned as an object.
  101. Defaults to `false`.
  102. [role="child_attributes"]
  103. [[scroll-api-request-body]]
  104. ==== {api-request-body-title}
  105. `scroll`::
  106. (Optional, <<time-units,time value>>)
  107. Period to retain the <<scroll-search-context,search context>> for scrolling. See
  108. <<scroll-search-results>>.
  109. +
  110. This value overrides the duration set by the original search API request's
  111. `scroll` parameter.
  112. +
  113. By default, this value cannot exceed `1d` (24 hours). You can change
  114. this limit using the `search.max_keep_alive` cluster-level setting.
  115. +
  116. IMPORTANT: You can also specify this value using the `scroll` query
  117. parameter. If both parameters are specified, only the query parameter is used.
  118. [[scroll-api-scroll-id-param]]
  119. `scroll_id`::
  120. (Required, string)
  121. Scroll ID for the search.
  122. [role="child_attributes"]
  123. [[scroll-api-response-body]]
  124. ==== {api-response-body-title}
  125. The scroll API returns the same response body as the search API. See the search
  126. API's <<search-api-response-body,response body parameters>>.