How to Delete Index in ElasticSearch?

Connect with

How to Delete Index in ElasticSearchLearn how to delete index in elasticSearch using. Delete either documents or type or index using browser, cUrl, postman or rest client. delete carefully on production environment.

1. Delete Index in ElasticSearch

When you get a chance to delete either documents or type or index, do it very carefully. How to delete an index in elastic search is a straight forward but do this very carefully, specially in a production environment. In this post, I tried to demonstrate how to delete index and its indexed content in elastic search.
You can delete using cURL or visually using one of the many tools that open source enthusiasts have created for Elastic search. e.g. using the head plugin, using fiddler, using rest client, using postman rest client, or any other utility tool or any software like Java or anoth another.

2. Delete different aspect in elasticSearch

By end of this post you can learn following which has different aspect of delete index in elasticsearch.

  • how to delete Index by index name in elastic search?
  • how to delete by type in elastic search?
  • how to delete more than one index by using wildcard (*)?
  • how to delete index by using Rest Client ?

3. Delete Index By Using cURL

Note: here , after port number (9200) , location which is an index name of elastic and restro is type, which comes under index name “location” and at end of the path param a document id.

You get reply from curl output as to whether this was successful or not.

4. Delete by type in Elastic

Delete by type by leaving documentID in the url.

curl -XDELETE localhost:9200/location/restro

5. Delete Index by index name

In the below query location is name of index, which delete all the index data from location index. Once you delete index , it means you deleted all of associated type under that index, do it very carefully.

 
curl -XDELETE [your_host]:9200/[your_index]

for example;

 
curl -XDELETE localhost:9200/location

6. Delete more than one index by using wildcard (*)

do this very carefully because of using wildcard option to delete index in elastic search.

curl -XDELETE localhost:9200/.oca* 

7. Delete Index By Using Rest Client

Service Input:

  1. Service URL: http://localhost:9200/myindex
  2. http method : Delete
  3. Content-Type: application/json

Service Output:

  1. Http response: 200 Ok
  2. JSON output
{
"acknowledged": true
}

Once deleted and you are trying to access again, you can get following error

{  
   "error":{  
      "root_cause":[  
         {  
            "type":"index_not_found_exception",
            "reason":"no such index",
            "index":"myindex",
            "resource.type":"index_or_alias",
            "resource.id":"myindex"
         }
      ],
      "type":"index_not_found_exception",
      "reason":"no such index",
      "index":"myindex",
      "resource.type":"index_or_alias",
      "resource.id":"myindex"
   },
   "status":404
}

8. Reference

elastic.co for more details.
I hope you enjoyed this post to delete index in elasticSearch, visit ElasticSearch tutorial for more details.
Write your suggestions here to improve this post. Happy Learning! 🙂


Connect with

2 thoughts on “How to Delete Index in ElasticSearch?”

  1. Pingback: Anu

  2. Pingback: rakhi

Leave a Comment

Your email address will not be published. Required fields are marked *