0

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.
https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html

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

kibana:

GET encodedIndexName 
DELETE encodedIndexName 
singla_02
  • 23
  • 6
  • It probably would help to see some code that leads to your error message :) – webwurst Mar 07 '19 at 18:05
  • String indexName = "<" + indexNameStaticPart + "{now/d-30d{MMddYYYY}}>"; encodedIndexName = UriEncoder.encode( indexName ).replace( "/", "%2F" ); AcknowledgedResponse response = client.admin().indices().delete( new DeleteIndexRequest( encodedIndexName ) ).actionGet(); – singla_02 Mar 07 '19 at 18:14
  • You might be interested in reading about Curator: https://www.elastic.co/guide/en/elasticsearch/client/curator/current/about-features.html It is a tool that you can install that will automatically delete old indices for you, among other features – IanGabes Mar 07 '19 at 18:17
  • Yeah but I am curious to know why this is not working out – singla_02 Mar 07 '19 at 18:32
  • plus we also need to schedule job to perform index deletion – singla_02 Mar 07 '19 at 19:01