1

我正在使用 logstash 为 ES 填充来自我们在多台机器上的实时服务的一些指标。Logstash 每天都会创建一个新索引,我发现在不指定索引的情况下查询 ES 运行缓慢。(我目前维持 5 天的指数)。如果我指定特定索引,例如今天

.es(index=logstash-2018.01.15, q= examplequery

它运行得非常快有没有办法可以使用日期字段指定今天的索引?

例如

.es(index=logstash-'get date', q= examplequery
4

2 回答 2

2

您可以使用查询来获取今天日期的索引:

 .es(index='<logstash-{now/d}>')

一个有趣的读物,其中包含弹性搜索中可用的所有选项,以在索引名称中包含日期数学:

https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html

于 2018-01-15T13:44:30.903 回答
0

通过查看语法,我猜您正在使用 Timelion 或使用查询字符串的东西。这里有一个很好的教程,其中包括指定索引模式:
https://www.elastic.co/blog/timelion-tutorial-from-zero-to-hero
在你的情况下,它将是

.es(index=logstash-*, q= examplequery

或者

.es(index=logstash-2018.01.*, q= examplequery

如果您需要今年 1 月并且索引模式是“logstash-YYYY.MM.dd”

于 2018-01-15T10:05:39.623 回答