2017-07-03 04:48:16 -04:00
|
|
|
[[java-rest-high-document-delete]]
|
2017-07-04 04:58:57 -04:00
|
|
|
=== Delete API
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
[[java-rest-high-document-delete-request]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Delete Request
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
A `DeleteRequest` requires the following arguments:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Index
|
|
|
|
<2> Type
|
|
|
|
<3> Document id
|
|
|
|
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Optional arguments
|
2017-07-03 04:48:16 -04:00
|
|
|
The following arguments can optionally be provided:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-routing]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Routing value
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-timeout]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Timeout to wait for primary shard to become available as a `TimeValue`
|
|
|
|
<2> Timeout to wait for primary shard to become available as a `String`
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-refresh]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
|
|
|
|
<2> Refresh policy as a `String`
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-request-version-type]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Version type
|
|
|
|
|
|
|
|
[[java-rest-high-document-delete-sync]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Synchronous Execution
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute]
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[[java-rest-high-document-delete-async]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Asynchronous Execution
|
2017-07-03 04:48:16 -04:00
|
|
|
|
2018-02-01 11:56:13 -05:00
|
|
|
The asynchronous execution of a delete request requires both the `DeleteRequest`
|
|
|
|
instance and an `ActionListener` instance to be passed to the asynchronous
|
|
|
|
method:
|
|
|
|
|
2017-07-03 04:48:16 -04:00
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-async]
|
|
|
|
--------------------------------------------------
|
2018-02-01 11:56:13 -05:00
|
|
|
<1> The `DeleteRequest` to execute and the `ActionListener` to use when
|
|
|
|
the execution completes
|
|
|
|
|
|
|
|
The asynchronous method does not block and returns immediately. Once it is
|
|
|
|
completed the `ActionListener` is called back using the `onResponse` method
|
|
|
|
if the execution successfully completed or using the `onFailure` method if
|
|
|
|
it failed.
|
|
|
|
|
|
|
|
A typical listener for `DeleteResponse` looks like:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-execute-listener]
|
|
|
|
--------------------------------------------------
|
2017-07-03 04:48:16 -04:00
|
|
|
<1> Called when the execution is successfully completed. The response is
|
2017-07-05 05:57:57 -04:00
|
|
|
provided as an argument
|
|
|
|
<2> Called in case of failure. The raised exception is provided as an argument
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
[[java-rest-high-document-delete-response]]
|
2017-07-04 04:58:57 -04:00
|
|
|
==== Delete Response
|
2017-07-03 04:48:16 -04:00
|
|
|
|
|
|
|
The returned `DeleteResponse` allows to retrieve information about the executed
|
|
|
|
operation as follows:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-response]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Handle the situation where number of successful shards is less than
|
|
|
|
total shards
|
|
|
|
<2> Handle the potential failures
|
|
|
|
|
|
|
|
|
|
|
|
It is also possible to check whether the document was found or not:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-notfound]
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> Do something if the document to be deleted was not found
|
|
|
|
|
|
|
|
If there is a version conflict, an `ElasticsearchException` will
|
|
|
|
be thrown:
|
|
|
|
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
|
|
--------------------------------------------------
|
|
|
|
include-tagged::{doc-tests}/CRUDDocumentationIT.java[delete-conflict]
|
|
|
|
--------------------------------------------------
|
2017-07-05 05:57:57 -04:00
|
|
|
<1> The raised exception indicates that a version conflict error was returned
|
2017-07-03 04:48:16 -04:00
|
|
|
|