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", ...
Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.