OpenSearch/docs/java-api/docs/delete.asciidoc
Julie Tibshirani f854330e06
Make sure to use the type _doc in the REST documentation. (#34662)
* Replace custom type names with _doc in REST examples.
* Avoid using two mapping types in the percolator docs.
* Rename doc -> _doc in the main repository README.
* Also replace some custom type names in the HLRC docs.
2018-10-22 11:54:04 -07:00

43 lines
1.5 KiB
Plaintext

[[java-docs-delete]]
=== Delete API
The delete API allows one to delete a typed JSON document from a specific
index based on its id. The following example deletes the JSON document
from an index called twitter, under a type called `_doc`, with id valued
1:
[source,java]
--------------------------------------------------
DeleteResponse response = client.prepareDelete("twitter", "_doc", "1").get();
--------------------------------------------------
For more information on the delete operation, check out the
{ref}/docs-delete.html[delete API] docs.
[[java-docs-delete-by-query]]
=== Delete By Query API
The delete by query API allows one to delete a given set of documents based on
the result of a query:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{client-reindex-tests}/ReindexDocumentationIT.java[delete-by-query-sync]
--------------------------------------------------
<1> query
<2> index
<3> execute the operation
<4> number of deleted documents
As it can be a long running operation, if you wish to do it asynchronously, you can call `execute` instead of `get`
and provide a listener like:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{client-reindex-tests}/ReindexDocumentationIT.java[delete-by-query-async]
--------------------------------------------------
<1> query
<2> index
<3> listener
<4> number of deleted documents