ElasticSearch - 不设置日期类型

ElasticSearch - not setting the date type

我正在尝试 ELK 堆栈,到目前为止还不错 :)

关于解析日期字段并将其发送到 ElasticSearch,我遇到了 运行 的奇怪情况。我设法解析了该字段,它确实是在 ElasticSearch 中创建的,但它总是以字符串形式结束。 我尝试了很多不同的组合。我也尝试了很多不同的人建议的东西,但我还是失败了。

这是我的设置:

来自Filebeat的字符串:

[2017-04-26 09:40:33] security.DEBUG: Stored the security token in the session. {"key":"securitysecured_area"} []

[2017-04-26 09:50:42] request.INFO: Matched route "home_logged_in". {"route_parameters":{"controller":"AppBundle\Controller\HomeLoggedInController::showAction","locale":"de","route":"homelogged_in"},"request_uri":"https://qa.someserver.de/de/home"} []

logstash解析部分:

if [@metadata][type] == "feprod" or [@metadata][type] == "feqa"{
 grok {
   match => { "message" => "%{TIMESTAMP_ISO8601:logdate}" }
 }
date {
#timezone => "Europe/Berlin"
match => [ "logdate", "yyyy-MM-dd HH:mm:ss"]
  }
}

根据文档,我的@timestamp 字段应该被 logdate 值覆盖。但它没有发生。

在 ElasticSearch 中,我可以看到正在创建字段 logdate,它的值为 2017-04-26 09:40:33,但它的类型是字符串。

我总是从零开始创建索引,我先删除它然后让 logstash 填充它。

我需要用实际日期(不是索引时的日期)覆盖 @timestamp,或者使用日期类型创建 logdate 字段。两个都不错

除非您在未显示的地方明确添加 [@metadata][type],否则这是您的问题。它不是默认设置的,[type] 是根据您输入的 'type =>' 参数默认设置的。

您可以用一个最小的完整示例来验证这一点:

input {
    stdin {
        type=>'feprod'
    }
}
filter {
    if [@metadata][type] == "feprod" or [@metadata][type] == "feqa"{
        grok {
            match => { "message" => "%{TIMESTAMP_ISO8601:logdate}" }
        }
        date {
            match => [ "logdate", "yyyy-MM-dd HH:mm:ss"]
        }
    }
}

output {
    stdout { codec => "rubydebug" }
}

和运行它:

echo '[2017-04-26 09:40:33] security.DEBUG: Stored the security token in the session. {"key":"securitysecured_area"} []' | bin/logstash -f test.conf

并得到输出:

{
    "@timestamp" => 2017-05-02T15:15:05.875Z,
      "@version" => "1",
          "host" => "xxxxxxxxx",
       "message" => "[2017-04-26 09:40:33] security.DEBUG: Stored the security     token in the session. {\"key\":\"securitysecured_area\"} []",
          "type" => "feprod",
          "tags" => []
}

如果你只使用 if [type] ==...它会工作得很好。

{
    "@timestamp" => 2017-04-26T14:40:33.000Z,
       "logdate" => "2017-04-26 09:40:33",
      "@version" => "1",
          "host" => "xxxxxxxxx",
       "message" => "[2017-04-26 09:40:33] security.DEBUG: Stored the security token in the session. {\"key\":\"securitysecured_area\"} []",
          "type" => "feprod",
          "tags" => []
}