flush.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. [[java-rest-high-flush]]
  2. === Flush API
  3. [[java-rest-high-flush-request]]
  4. ==== Flush Request
  5. A `FlushRequest` can be applied to one or more indices, or even on `_all` the indices:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-request]
  9. --------------------------------------------------
  10. <1> Flush one index
  11. <2> Flush multiple indices
  12. <3> Flush all the indices
  13. ==== Optional arguments
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-request-indicesOptions]
  17. --------------------------------------------------
  18. <1> Setting `IndicesOptions` controls how unavailable indices are resolved and
  19. how wildcard expressions are expanded
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-request-wait]
  23. --------------------------------------------------
  24. <1> Set the `wait_if_ongoing` flag to `true`
  25. ["source","java",subs="attributes,callouts,macros"]
  26. --------------------------------------------------
  27. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-request-force]
  28. --------------------------------------------------
  29. <1> Set the `force` flag to `true`
  30. [[java-rest-high-flush-sync]]
  31. ==== Synchronous Execution
  32. ["source","java",subs="attributes,callouts,macros"]
  33. --------------------------------------------------
  34. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-execute]
  35. --------------------------------------------------
  36. [[java-rest-high-flush-async]]
  37. ==== Asynchronous Execution
  38. The asynchronous execution of a flush request requires both the `FlushRequest`
  39. instance and an `ActionListener` instance to be passed to the asynchronous
  40. method:
  41. ["source","java",subs="attributes,callouts,macros"]
  42. --------------------------------------------------
  43. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-execute-async]
  44. --------------------------------------------------
  45. <1> The `FlushRequest` to execute and the `ActionListener` to use when
  46. the execution completes
  47. The asynchronous method does not block and returns immediately. Once it is
  48. completed the `ActionListener` is called back using the `onResponse` method
  49. if the execution successfully completed or using the `onFailure` method if
  50. it failed.
  51. A typical listener for `FlushResponse` looks like:
  52. ["source","java",subs="attributes,callouts,macros"]
  53. --------------------------------------------------
  54. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-execute-listener]
  55. --------------------------------------------------
  56. <1> Called when the execution is successfully completed. The response is
  57. provided as an argument
  58. <2> Called in case of failure. The raised exception is provided as an argument
  59. [[java-rest-high-flush-response]]
  60. ==== Flush Response
  61. The returned `FlushResponse` allows to retrieve information about the
  62. executed operation as follows:
  63. ["source","java",subs="attributes,callouts,macros"]
  64. --------------------------------------------------
  65. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-response]
  66. --------------------------------------------------
  67. <1> Total number of shards hit by the flush request
  68. <2> Number of shards where the flush has succeeded
  69. <3> Number of shards where the flush has failed
  70. <4> A list of failures if the operation failed on one or more shards
  71. By default, if the indices were not found, an `ElasticsearchException` will be thrown:
  72. ["source","java",subs="attributes,callouts,macros"]
  73. --------------------------------------------------
  74. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-notfound]
  75. --------------------------------------------------
  76. <1> Do something if the indices to be flushed were not found