delete.asciidoc 4.9 KB

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