Delete By Query API

Deprecated in 1.5.3.

The delete by query API will be removed in 2.0: it is problematic since it silently forces a refresh which can quickly cause OutOfMemoryError during concurrent indexing, and can also cause primary and replica to become inconsistent. Instead, use the scroll/scan API to find all matching ids and then issue a bulk request to delete them.

The delete by query API allows one to delete documents from one or more indices and one or more types based on a query. Here is an example:

import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;

DeleteByQueryResponse response = client.prepareDeleteByQuery("test")
        .setQuery(termQuery("_type", "type1"))

For more information on the delete by query operation, check out the delete_by_query API docs.