I'm approaching ElastichSearch with a Java client. I'm trying to delete an entire index. I'm able to delete a single document with the following code:
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();
I would like to delete all documents for a given index in a single instruction. Note that I'm using the version 2.2.
Thanks
EDIT: I've found a similar question but it refers to an old API version. I'm currently working with version 2.2.
The easiest way would be to delete your index, then recreate it.
DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest("your-index")).actionGet()
then
client.admin().indices().prepareCreate("your-index").get();
This will work with the 2.2 api
Same solution as in maximede's answer but using newer version of RestHighLevelClient
(non depreciated):
// delete current index
var deleteRequest = new DeleteIndexRequest("index-name");
client.indices().delete(deleteRequest, RequestOptions.DEFAULT);
// create new one
CreateIndexRequest request = new CreateIndexRequest("index-name");
client.indices().create(request, RequestOptions.DEFAULT);
Please make sure to import from the right package:
org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest
org.elasticsearch.client.indices.CreateIndexRequest;
Works fine with micronaut framework io.micronaut.elasticsearch:micronaut-elasticsearch:4.0.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.