force_merge.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. [[java-rest-high-force-merge]]
  2. === Force Merge API
  3. [[java-rest-high-force-merge-request]]
  4. ==== Force merge Request
  5. A `ForceMergeRequest` 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[force-merge-request]
  9. --------------------------------------------------
  10. <1> Force merge one index
  11. <2> Force merge multiple indices
  12. <3> Force merge all the indices
  13. ==== Optional arguments
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-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[force-merge-request-segments-num]
  23. --------------------------------------------------
  24. <1> Set `max_num_segments` to control the number of segments to merge down to.
  25. ["source","java",subs="attributes,callouts,macros"]
  26. --------------------------------------------------
  27. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-request-only-expunge-deletes]
  28. --------------------------------------------------
  29. <1> Set the `only_expunge_deletes` flag to `true`
  30. ["source","java",subs="attributes,callouts,macros"]
  31. --------------------------------------------------
  32. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-request-flush]
  33. --------------------------------------------------
  34. <1> Set the `flush` flag to `true`
  35. [[java-rest-high-force-merge-sync]]
  36. ==== Synchronous Execution
  37. ["source","java",subs="attributes,callouts,macros"]
  38. --------------------------------------------------
  39. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-execute]
  40. --------------------------------------------------
  41. [[java-rest-high-force-merge-async]]
  42. ==== Asynchronous Execution
  43. The asynchronous execution of a force merge request requires both the `ForceMergeRequest`
  44. instance and an `ActionListener` instance to be passed to the asynchronous
  45. method:
  46. ["source","java",subs="attributes,callouts,macros"]
  47. --------------------------------------------------
  48. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-execute-async]
  49. --------------------------------------------------
  50. <1> The `ForceMergeRequest` to execute and the `ActionListener` to use when
  51. the execution completes
  52. The asynchronous method does not block and returns immediately. Once it is
  53. completed the `ActionListener` is called back using the `onResponse` method
  54. if the execution successfully completed or using the `onFailure` method if
  55. it failed.
  56. A typical listener for `ForceMergeResponse` looks like:
  57. ["source","java",subs="attributes,callouts,macros"]
  58. --------------------------------------------------
  59. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-execute-listener]
  60. --------------------------------------------------
  61. <1> Called when the execution is successfully completed. The response is
  62. provided as an argument
  63. <2> Called in case of failure. The raised exception is provided as an argument
  64. [[java-rest-high-force-merge-response]]
  65. ==== Force Merge Response
  66. The returned `ForceMergeResponse` allows to retrieve information about the
  67. executed operation as follows:
  68. ["source","java",subs="attributes,callouts,macros"]
  69. --------------------------------------------------
  70. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-response]
  71. --------------------------------------------------
  72. <1> Total number of shards hit by the force merge request
  73. <2> Number of shards where the force merge has succeeded
  74. <3> Number of shards where the force merge has failed
  75. <4> A list of failures if the operation failed on one or more shards
  76. By default, if the indices were not found, an `ElasticsearchException` will be thrown:
  77. ["source","java",subs="attributes,callouts,macros"]
  78. --------------------------------------------------
  79. include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[force-merge-notfound]
  80. --------------------------------------------------
  81. <1> Do something if the indices to be force merged were not found