elasticsearch - logstash的elasticsearch index date从哪里来?

标签 elasticsearch logstash

来自 the docs :

Default value is "logstash-%{+YYYY.MM.dd}"

我想知道 logstash 从哪里获取 YYYY.MM.dd 的信息?是@timestamp 字段吗?如果是这样,是否可以告诉它使用不同的字段(例如@mydate)?

最佳答案

索引YYYY.MM.dd是根据@timestamp时间。

可以引用elasticsearch.rb关于打印 logstash 索引的“event.sprintf”。

index = event.sprintf(@index)

然后就可以研究了event.rb看看 sprintf 做了什么。

t = @data["@timestamp"]
    formatter = org.joda.time.format.DateTimeFormat.forPattern(key[1 .. -1])\
      .withZone(org.joda.time.DateTimeZone::UTC)
    #next org.joda.time.Instant.new(t.tv_sec * 1000 + t.tv_usec / 1000).toDateTime.toString(formatter)
    # Invoke a specific Instant constructor to avoid this warning in JRuby
    #  > ambiguous Java methods found, using org.joda.time.Instant(long)
    org.joda.time.Instant.java_class.constructor(Java::long).new_instance(
      t.tv_sec * 1000 + t.tv_usec / 1000
    ).to_java.toDateTime.toString(formatter)

所以,如果你想让索引跟随你自己的字段,你必须修改 event.rb 以使用你自己的字段而不是时间戳。或者您可以将时间戳值更改为您自己的字段时间。

关于elasticsearch - logstash的elasticsearch index date从哪里来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536908/

相关文章:

php - elasticsearch使用php API获取索引中的文档总数

elasticsearch - 如何从日志文件路径中提取变量,在Logstash中测试模式的日志文件名?

elasticsearch - Logstash 中的节拍输入正在丢失字段

php - Elasticsearch 1.4和Drupal 7:在查询中使用数组

ubuntu - 如何在 ubuntu 18 上将演示请求发布到 elasticsearch

elasticsearch - Spring Data Elasticsearch嵌套字段多匹配查询

elasticsearch - 为什么logstash不产生日志?

elasticsearch - 如何使用logstash处理由空格分隔的文本文件?

azure - Logstash + Azure 事件中心

ruby-on-rails - 升级后Searchkick无法将索引映射到模型