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>/_doc/<id>

To delete a document, we will perform the following steps:

  1. If we consider the order indexed in the Indexing a document recipe, the call to delete a document will be as follows:
DELETE /myindex/_doc/2qLrAfPVQvCRMe7Ku8r0Tw
  1. The result returned by Elasticsearch should be as follows:
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "2qLrAfPVQvCRMe7Ku8r0Tw",
"_version" : 2,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1
}
  1. If the record is missing, a 404 is returned as the status code, and the return JSON will be as follows:
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "2qLrAfPVQvCRMe7Ku8r0Tw",
"_version" : 3,
"result" : "not_found",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}