【问题标题】:delete time based indices on elastic search older than 30 days using date math expression in JAVA gives indexNotExists exception使用 JAVA 中的日期数学表达式删除弹性搜索中超过 30 天的基于时间的索引会给出索引不存在异常
【发布时间】:2019-03-07 17:55:33
【问题描述】:

想要使用 JAVA 中的日期数学表达式删除早于某些特定(比如 30)天的弹性搜索中基于时间的索引。

尝试使用 Transaport Client 在我们的 Spring Boot 应用程序中实现以下方法,但获取索引不存在异常。
https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html

当使用相同的 URI 编码索引名称(传递给 DELETE INDEX API)在 kibana 上使用查询 GET uri_encoded_index_name 搜索索引时,表明索引存在。

我有什么遗漏的吗?
有没有更好的方法可以在不使用馆长和通配符的情况下做到这一点?

代码sn-p:

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 

【问题讨论】:

  • 查看一些导致您的错误消息的代码可能会有所帮助:)
  • 字符串 indexName = ""; encodeIndexName = UriEncoder.encode( indexName ).replace( "/", "%2F" ); AcknowledgedResponse response = client.admin().indices().delete(new DeleteIndexRequest(codedIndexName)).actionGet();
  • 您可能有兴趣了解 Curator:elastic.co/guide/en/elasticsearch/client/curator/current/… 这是一个您可以安装的工具,它会自动为您删除旧索引以及其他功能
  • 是的,但我很想知道为什么这不起作用
  • 另外我们还需要安排作业来执行索引删除

标签: elasticsearch kibana elasticsearch-java-api date-math elasticsearch-indices


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-30
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2021-03-06
  • 1970-01-01
相关资源
最近更新 更多