Delete time based indices on elastic search older than 30 days using date math expression in JAVA gives indexNotExists exception

want to delete time based indices on elastic search older than some specific (let's say 30) days using date math expression in JAVA.

Trying to implement following approach in our spring boot application using Transaport Client but getting index not exist exception.

When the same URI encoded index name (which is passed to DELETE INDEX API) is used to search index using query GET uri_encoded_index_name on kibana, It shows that index exists.

Is there something I am missing out ?
Is there any better approach to do that without using curator and wilcard characters?

code snippet:

String indexName = "<" + indexNameStaticPart + "{now/d-30d{MMddYYYY}}>";
String encodedIndexName = UriEncoder.encode( indexName ).replace( "/", "%2F" );
AcknowledgedResponse response = client.admin().indices().delete( new DeleteIndexRequest( encodedIndexName ) ).actionGet();  

encodedIndexName = %3Cstring__string_string__%7Bnow%2Fd-30d%7BMMddyyyy%7D%7D%3E


GET encodedIndexName 
DELETE encodedIndexName

Life is easy with elastic curator

Yeah, I know but I was just wondering why this is not working.

What do you have in encodedIndexName? Could you print its value?


It does not look like an index name unless indexNameStaticPart is really string__string_string.

What gives

GET /_cat/indices?v

Do you have an index named string__string_string__02072019?


GET /_cat/indices?v

shows list of all the indices, among them one is string__string_string__02072019


GET %3Cstring__string_string__%7Bnow%2Fd-30d%7BMMddyyyy%7D%7D%3E

shows the index mappings and settings

Did you try without doing the url encoding?

1 Like

Yeah I just. It worked out. Thanks man.

Any idea why is it different from the provided documentation ?

Which documentation?

1 Like

I see. I believe that the high level client does encoding if needed.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.