In the previous chapter we saw how to delete a document. Deleting a document is very fast but we need to know the document ID.
ElasticSearch provides a call to delete all the documents that match a query.
You need a working ElasticSearch cluster and an index populated with the script available in online code.
For executing a delete by query, we need to perform the following steps:
From command line, we need to execute the following query:
curl -XDELETE 'http://127.0.0.1:9200/test-index/test-type/_query' -d '{"match_all":{}}'
The result returned by ElasticSearch, if everything is all right, should be as follows:
{ "ok" : true, "_indices" : { "test-index" : { "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 } } } }
The result is composed by the
ok
result (a Boolean type) and the shards status at the time of the delete by query.