logstash grok TIMESTAMP_ISO8601 类型?

logstash grok TIMESTAMP_ISO8601 type?

我有一个简单的 logstash grok 过滤器:

filter {
  grok {
    match => { "message" => "^%{TIMESTAMP_ISO8601:timestamp} %{NOTSPACE:name} %{WORD:level} %{SPACE} %{GREEDYDATA:message}$" }
    overwrite => [ "message" ]
  }
}

这有效,它解析我的日志,但根据 Kibana,时间戳值以数据类型 string 输出。

logstash @timestamp 字段的数据类型为 date

grok 文档说可以指定数据类型转换,但只支持 int 和 float:

If you wish to convert a semantic’s data type, for example change a string to an integer then suffix it with the target data type. For example %{NUMBER:num:int} which converts the num semantic from a string to an integer. Currently the only supported conversions are int and float.

这表明我应该将其保留为字符串,但是,如果索引支持日期时间值,您为什么不希望它作为日期时间正确存储和排序?

可以,但需要另一个过滤器将其转换为日期。

filter {
  date {
    match => [ "timestamp", ISO8601 ]
  }
}

通常的用法是这样设置@timestamp字段。但是如果你想在另一个领域这样做并且单独留下 @timestamp

filter {
  date {
    match  => [ "timestamp", ISO8601 ]
    target => "target_timestamp"
  }
}

这将为您提供一个名为 target_timestamp 的字段,其中包含您要查找的 ElasticSearch 数据类型。