Sunday, 27 December 2015

Delete Index in Elasticsearch

An existing index/type/document in Elasticsearch can be deleted either by using REST service or by using the Java API invocation.
Below are the scripts to delete the index.

Delete complete index :

REST  Service:
$ curl -XDELETE 'http://localhost:9200/<indexname>'

Java API :
client.admin().indices().delete(new DeleteIndexRequest("<indexname>")).actionGet();

Delete a type in index   :

REST Service :
$ curl -XDELETE 'http://localhost:9200/<indexname>/<typename>'

Java API :
client.prepareDelete().setIndex("<indexname>").setType("<typename>").setId("*").execute().actionGet();

Delete a particular document :

REST Service :
$ curl -XDELETE 'http://localhost:9200/<indexname>/<typename>/<documentId>

Java API:
client.prepareDelete().setIndex("<indexname>").setType("<typename>").setId("<documentId>").execute().actionGet();

Note:

The delete operation cannot be rolled back at any point. So make sure to double check the delete command before execution.

No comments:

Post a Comment