delete.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. [[java-rest-high-document-delete]]
  2. === Delete API
  3. [[java-rest-high-document-delete-request]]
  4. ==== Delete Request
  5. A `DeleteRequest` requires the following arguments:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request]
  9. --------------------------------------------------
  10. <1> Index
  11. <2> Type
  12. <3> Document id
  13. ==== Optional arguments
  14. The following arguments can optionally be provided:
  15. ["source","java",subs="attributes,callouts,macros"]
  16. --------------------------------------------------
  17. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-routing]
  18. --------------------------------------------------
  19. <1> Routing value
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-timeout]
  23. --------------------------------------------------
  24. <1> Timeout to wait for primary shard to become available as a `TimeValue`
  25. <2> Timeout to wait for primary shard to become available as a `String`
  26. ["source","java",subs="attributes,callouts,macros"]
  27. --------------------------------------------------
  28. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-refresh]
  29. --------------------------------------------------
  30. <1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
  31. <2> Refresh policy as a `String`
  32. ["source","java",subs="attributes,callouts,macros"]
  33. --------------------------------------------------
  34. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version]
  35. --------------------------------------------------
  36. <1> Version
  37. ["source","java",subs="attributes,callouts,macros"]
  38. --------------------------------------------------
  39. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version-type]
  40. --------------------------------------------------
  41. <1> Version type
  42. [[java-rest-high-document-delete-sync]]
  43. ==== Synchronous Execution
  44. ["source","java",subs="attributes,callouts,macros"]
  45. --------------------------------------------------
  46. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute]
  47. --------------------------------------------------
  48. [[java-rest-high-document-delete-async]]
  49. ==== Asynchronous Execution
  50. The asynchronous execution of a delete request requires both the `DeleteRequest`
  51. instance and an `ActionListener` instance to be passed to the asynchronous
  52. method:
  53. ["source","java",subs="attributes,callouts,macros"]
  54. --------------------------------------------------
  55. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-async]
  56. --------------------------------------------------
  57. <1> The `DeleteRequest` to execute and the `ActionListener` to use when
  58. the execution completes
  59. The asynchronous method does not block and returns immediately. Once it is
  60. completed the `ActionListener` is called back using the `onResponse` method
  61. if the execution successfully completed or using the `onFailure` method if
  62. it failed.
  63. A typical listener for `DeleteResponse` looks like:
  64. ["source","java",subs="attributes,callouts,macros"]
  65. --------------------------------------------------
  66. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-listener]
  67. --------------------------------------------------
  68. <1> Called when the execution is successfully completed. The response is
  69. provided as an argument
  70. <2> Called in case of failure. The raised exception is provided as an argument
  71. [[java-rest-high-document-delete-response]]
  72. ==== Delete Response
  73. The returned `DeleteResponse` allows to retrieve information about the executed
  74. operation as follows:
  75. ["source","java",subs="attributes,callouts,macros"]
  76. --------------------------------------------------
  77. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-response]
  78. --------------------------------------------------
  79. <1> Handle the situation where number of successful shards is less than
  80. total shards
  81. <2> Handle the potential failures
  82. It is also possible to check whether the document was found or not:
  83. ["source","java",subs="attributes,callouts,macros"]
  84. --------------------------------------------------
  85. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-notfound]
  86. --------------------------------------------------
  87. <1> Do something if the document to be deleted was not found
  88. If there is a version conflict, an `ElasticsearchException` will
  89. be thrown:
  90. ["source","java",subs="attributes,callouts,macros"]
  91. --------------------------------------------------
  92. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-conflict]
  93. --------------------------------------------------
  94. <1> The raised exception indicates that a version conflict error was returned