delete.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. [[java-docs-delete]]
  2. === Delete API
  3. The delete API allows one to delete a typed JSON document from a specific
  4. index based on its id. The following example deletes the JSON document
  5. from an index called twitter, under a type called `_doc`, with id valued
  6. 1:
  7. [source,java]
  8. --------------------------------------------------
  9. DeleteResponse response = client.prepareDelete("twitter", "_doc", "1").get();
  10. --------------------------------------------------
  11. For more information on the delete operation, check out the
  12. {ref}/docs-delete.html[delete API] docs.
  13. [[java-docs-delete-by-query]]
  14. === Delete By Query API
  15. The delete by query API allows one to delete a given set of documents based on
  16. the result of a query:
  17. ["source","java",subs="attributes,callouts,macros"]
  18. --------------------------------------------------
  19. include-tagged::{client-reindex-tests}/ReindexDocumentationIT.java[delete-by-query-sync]
  20. --------------------------------------------------
  21. <1> query
  22. <2> index
  23. <3> execute the operation
  24. <4> number of deleted documents
  25. As it can be a long running operation, if you wish to do it asynchronously, you can call `execute` instead of `get`
  26. and provide a listener like:
  27. ["source","java",subs="attributes,callouts,macros"]
  28. --------------------------------------------------
  29. include-tagged::{client-reindex-tests}/ReindexDocumentationIT.java[delete-by-query-async]
  30. --------------------------------------------------
  31. <1> query
  32. <2> index
  33. <3> listener
  34. <4> number of deleted documents