Home » Java » spring boot – Problem in Delete Index by name from Elasticsearch using java clients-Exceptionshub

spring boot – Problem in Delete Index by name from Elasticsearch using java clients-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am using Elasticsearch 6.5.4 version and when I delete one index by its name using below codes it is working fine but when I try to search using the deleted index name instead of getting “no such index” message I get some documents which are present in some other indices.

But before deletion of that index when I search with the same query I got the results only from that index, strange!!!

1.Delete index using Low level Rest Client

Request req  = new Request("DELETE",  "/"+allData.getIndexName());
Response response = getElasticRestClient().performRequest(req);

2.Delete index using High Level Rest Client

DeleteIndexRequest request = new DeleteIndexRequest(allData.getIndexName());
AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);

I have tried both of these and in both the cases index got deleted successfully but facing the same issue while searching with the deleted indexname.

Now, I have deleted all the indices first and then checked for GET _cat/indices and GET _cat/aliases where I got “[]”.

Then I have created 2 indices with the name “action_movies” and “superhero_movies” and added 3 documents for each index.

1st index
2nd index

Now when I checked for GET _cat/aliases got [] as before.
And for GET _cat/indices got

["superhero_movies",
 "action_movies"]

Now when I searched the index “action_movies” and got following results
action_movies

with “superhero_movies” got following results
superhero_movies

Then deleted the index “action_movies” and repeated GET _cat/aliases and got []
then GET _cat/indices and got

["action_movies"]

And Finally I search for “action_movies” I got the following result(the documents belongs to the index “superhero_movies”) instead of “no such index”.

enter image description here

How to&Answers: