Deleting by query
In the Deleting a document
recipe from Chapter 4, Basic Operations, we saw how to delete a document()
. A document can be deleted very quickly, but it requires you to know the document ID.
ElasticSearch provides a call to delete all the documents that match a query.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_05/populate_query.sh
) available in the code bundle for this book.
How to do it...
In order to execute a DELETE
by query, perform the following steps:
Using the command line, execute a query, as follows:
curl -XDELETE 'http://127.0.0.1:9200/test-index/test-type/_query?pretty=true' -d '{"query":{"match_all":{}}}'
The following result should be returned by ElasticSearch, if everything works all right:
{ "_indices" : { "test-index" : { "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 } } } }
The result is composed of the shard's status at the time of the
DELETE
query...