delete-by-query.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. --
  2. :api: delete-by-query
  3. :request: DeleteByQueryRequest
  4. :response: DeleteByQueryResponse
  5. --
  6. [id="{upid}-{api}"]
  7. === Delete By Query API
  8. [id="{upid}-{api}-request"]
  9. ==== Delete By Query Request
  10. A +{request}+ can be used to delete documents from an index. It requires an
  11. existing index (or a set of indices) on which deletion is to be performed.
  12. The simplest form of a +{request}+ looks like this and deletes all documents
  13. in an index:
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{doc-tests-file}[{api}-request]
  17. --------------------------------------------------
  18. <1> Creates the +{request}+ on a set of indices.
  19. By default version conflicts abort the +{request}+ process but you can just
  20. count them with this:
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests-file}[{api}-request-conflicts]
  24. --------------------------------------------------
  25. <1> Set `proceed` on version conflict
  26. You can limit the documents by adding a query.
  27. ["source","java",subs="attributes,callouts,macros"]
  28. --------------------------------------------------
  29. include-tagged::{doc-tests-file}[{api}-request-query]
  30. --------------------------------------------------
  31. <1> Only copy documents which have field `user` set to `kimchy`
  32. It’s also possible to limit the number of processed documents by setting `maxDocs`.
  33. ["source","java",subs="attributes,callouts,macros"]
  34. --------------------------------------------------
  35. include-tagged::{doc-tests-file}[{api}-request-maxDocs]
  36. --------------------------------------------------
  37. <1> Only copy 10 documents
  38. By default +{request}+ uses batches of 1000. You can change the batch size
  39. with `setBatchSize`.
  40. ["source","java",subs="attributes,callouts,macros"]
  41. --------------------------------------------------
  42. include-tagged::{doc-tests-file}[{api}-request-scrollSize]
  43. --------------------------------------------------
  44. <1> Use batches of 100 documents
  45. +{request}+ can also be parallelized using `sliced-scroll` with `setSlices`:
  46. ["source","java",subs="attributes,callouts,macros"]
  47. --------------------------------------------------
  48. include-tagged::{doc-tests-file}[{api}-request-slices]
  49. --------------------------------------------------
  50. <1> set number of slices to use
  51. +{request}+ uses the `scroll` parameter to control how long it keeps the
  52. "search context" alive.
  53. ["source","java",subs="attributes,callouts,macros"]
  54. --------------------------------------------------
  55. include-tagged::{doc-tests-file}[{api}-request-scroll]
  56. --------------------------------------------------
  57. <1> set scroll time
  58. If you provide routing then the routing is copied to the scroll query, limiting the process to the shards that match
  59. that routing value.
  60. ["source","java",subs="attributes,callouts,macros"]
  61. --------------------------------------------------
  62. include-tagged::{doc-tests-file}[{api}-request-routing]
  63. --------------------------------------------------
  64. <1> set routing
  65. ==== Optional arguments
  66. In addition to the options above the following arguments can optionally be also provided:
  67. ["source","java",subs="attributes,callouts,macros"]
  68. --------------------------------------------------
  69. include-tagged::{doc-tests-file}[{api}-request-timeout]
  70. --------------------------------------------------
  71. <1> Timeout to wait for the delete by query request to be performed as a `TimeValue`
  72. ["source","java",subs="attributes,callouts,macros"]
  73. --------------------------------------------------
  74. include-tagged::{doc-tests-file}[{api}-request-refresh]
  75. --------------------------------------------------
  76. <1> Refresh index after calling delete by query
  77. ["source","java",subs="attributes,callouts,macros"]
  78. --------------------------------------------------
  79. include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
  80. --------------------------------------------------
  81. <1> Set indices options
  82. include::../execution.asciidoc[]
  83. [id="{upid}-{api}-response"]
  84. ==== Delete By Query Response
  85. The returned +{response}+ contains information about the executed operations and
  86. allows to iterate over each result as follows:
  87. ["source","java",subs="attributes,callouts,macros"]
  88. --------------------------------------------------
  89. include-tagged::{doc-tests-file}[{api}-response]
  90. --------------------------------------------------
  91. <1> Get total time taken
  92. <2> Check if the request timed out
  93. <3> Get total number of docs processed
  94. <4> Number of docs that were deleted
  95. <5> Number of batches that were executed
  96. <6> Number of skipped docs
  97. <7> Number of version conflicts
  98. <8> Number of times request had to retry bulk index operations
  99. <9> Number of times request had to retry search operations
  100. <10> The total time this request has throttled itself not including the current throttle time if it is currently sleeping
  101. <11> Remaining delay of any current throttle sleep or 0 if not sleeping
  102. <12> Failures during search phase
  103. <13> Failures during bulk index operation