Deleting a document
Deleting documents in ElasticSearch is possible in two ways: by using the DELETE call or the DELETE BY QUERY call; we will learn about it in the next chapter.
Getting ready
You will need a working ElasticSearch cluster and the indexed document of the Indexing a document recipe in this chapter.
How to do it...
The REST API URL is the same as the GET calls, but the HTTP method is DELETE:
http://<server>/<index_name>/<type_name>/<id>
To delete a document, we will perform the following steps:
If we consider the
order
index in the Indexing a document recipe, the call to delete a document will be:curl -XDELETE 'http://localhost:9200/myindex/order/2qLrAfPVQvCRMe7Ku8r0Tw'
The result returned by ElasticSearch should be:
{ "_id": "2qLrAfPVQvCRMe7Ku8r0Tw", "_index": "myindex", "_type": "order", "_version": 2, "found": true }
If the record is missing, a 404 error is returned as the status code and the return JSON will be:
{ "_id": "2qLrAfPVQvCRMe7Ku8r0Tw...