[Recipes] Deleting Elasticsearch Indices and Documents

Problem: 

Need to delete indices and documents created in previous steps. Need to selectively delete documents.

Solution Summary: 

We can send a DELETE http request to delete indices or documents. We can use the delete_by_query API to delete selectively. 

Solution Steps: 

Delete Document

DELETE /employee/_doc/1/

Resonse:

{
  "_index": "employee",
  "_type": "_doc",
  "_id": "1",
  "_version": 3,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "_seq_no": 16,
  "_primary_term": 1
}

 

Delete By Query

POST /employee/_delete_by_query
{
  "query": {
    "match": {
      "_id":2
    }
  }
}

Note: You can match against any field. _id is one of the metadata fields. Match queries will be discussed in detail later.

Additional Notes:

  1. Every time a batch of documents is found when using _delete_by_query, a corresponding bulk request is executed to delete all these documents.

  2. It is much more efficient to delete a whole index instead of deleting all documents with the Delete By Query API.

 

Delete Index

DELETE /employee

Recipe Tags: 

Learn Serverless from Serverless Programming Cookbook

Contact

Please first use the contact form or facebook page messaging to connect.

Offline Contact
We currently connect locally for discussions and sessions at Bangalore, India. Please follow us on our facebook page for details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.

About

CloudMaterials is my blog to share notes and learning materials on Cloud and Data Analytics. My current focus is on Microsoft Azure and Amazon Web Services (AWS).

I like to write and I try to document what I learn to share with others. I believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream