clear_cache.asciidoc 4.6 KB

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