The delete API allows you to delete JSON documents from a specified index by ID. There are two methods: ID-based data deletion and query-based data deletion.
1. Delete by ID
The following example shows how to delete a document whose index name is Twitter, its type is tweet, and its ID is 1:
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1") .execute() .actionGet();
Ii. Delete through query
The following example deletes all documents whose index name is productindex and whose title contains query:
QueryBuilder query = QueryBuilders.fieldQuery("title", "query"); client.prepareDeleteByQuery("productIndex").setQuery(query).execute().actionGet();
Set thread
When the deletion API is executed on the same node (when an API is executed in a shard, it is allocated to the same server), the deletion API allows you to set the thread mode (operationthreaded option) before execution ), the operationthreaded option enables this operation to be executed in another thread or in a requesting thread (assuming this API is still asynchronous. By default, operationthreaded is set to true, which means this operation will be executed in a different thread. The method to set to false is as follows:
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1") .setOperationThreaded(false) .execute() .actionGet();
Official documentation:
Http://www.elasticsearch.org/guide/reference/api/delete.html
Http://www.elasticsearch.org/guide/reference/java-api/delete.html