Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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'
    
  2. The result returned by ElasticSearch should be:

    {
      "_id": "2qLrAfPVQvCRMe7Ku8r0Tw",
      "_index": "myindex",
      "_type": "order",
      "_version": 2,
      "found": true
    }
  3. If the record is missing, a 404 error is returned as the status code and the return JSON will be:

    {
      "_id": "2qLrAfPVQvCRMe7Ku8r0Tw...