Deleting a document
Deleting documents in ElasticSearch is possible in two ways: using the delete call or the delete by query, which we'll see in the next chapter.
Getting ready
You need a working ElasticSearch cluster and the indexed document which we have discussed in the Indexing a document recipe.
How to do it...
The REST API URL is similar to that of GET calls, but the HTTP method is DELETE
:
http://<server>/<index_name>/<type_name>/<id>
For deleting a document, we need to perform the following steps:
If we consider the order indexed in the Indexing a document recipe, the call to delete a document will be as follows:
curl -XDELETE 'http://localhost:9200/myindex/order/2qLrAfPVQvCRMe7Ku8r0Tw'
The result returned by ElasticSearch will be as follows:
{ "_id": "2qLrAfPVQvCRMe7Ku8r0Tw", "_index": "myindex", "_type": "order", "_version": 2, "found": true, "ok": true }
The result, a part of the well-known parameter starting from
_
returns theok
status...