Distributed search elasticsearch Java API (4) -- delete index data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.