delete.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. ["source","java",subs="attributes,callouts,macros"]
  56. --------------------------------------------------
  57. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-async]
  58. --------------------------------------------------
  59. <1> Called when the execution is successfully completed. The response is
  60. provided as an argument.
  61. <2> Called in case of failure. The raised exception is provided as an argument.
  62. [[java-rest-high-document-delete-response]]
  63. ==== Delete Response
  64. The returned `DeleteResponse` allows to retrieve information about the executed
  65. operation as follows:
  66. ["source","java",subs="attributes,callouts,macros"]
  67. --------------------------------------------------
  68. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-response]
  69. --------------------------------------------------
  70. <1> Handle the situation where number of successful shards is less than
  71. total shards
  72. <2> Handle the potential failures
  73. It is also possible to check whether the document was found or not:
  74. ["source","java",subs="attributes,callouts,macros"]
  75. --------------------------------------------------
  76. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-notfound]
  77. --------------------------------------------------
  78. <1> Do something if the document to be deleted was not found
  79. If there is a version conflict, an `ElasticsearchException` will
  80. be thrown:
  81. ["source","java",subs="attributes,callouts,macros"]
  82. --------------------------------------------------
  83. include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-conflict]
  84. --------------------------------------------------
  85. <1> The raised exception indicates that a version conflict error was returned.