我们可以在elasticserch中自定义时间戳

时间:2018-02-04 14:10:43

标签: elasticsearch logstash elastic-stack

我有logstash和elasticsearch运行和索引,它使用创建的日期作为时间戳。我在日志中有一条格式为

的消息

t message 2018-01-21 23:55:00.266 INFO

我无法使用邮件中的时间戳进行索引。有什么方法可以实现这个目标吗? 我当前的logstash配置:

input {
  file {
    path => "/elk/*/*/*.log"
    type => "log"
    #start_position => "beginning"
    max_open_files => 80000
  }
}
output {
  elasticsearch {
    hosts => "localhost:9200"
  }
}

示例日志行:

2018-02-06 10:36:21.607 DEBUG [finer,3c5f365003b590ce,025357cdf9dbf3ac,true] 7 --- [nio-9095-exec-3] c.t.finexp.services.impl.MongoService : MongoService find one the collection: external_loanofficer with map input{"nmlsId":"87207"}

1 个答案:

答案 0 :(得分:1)

首先,您需要将时间戳移动到记录中的单独字段。我会使用logstash grok过滤器。

  

https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html

之后,您可以在Kibana中指定要用作时间戳的字段,或者您可以尝试使用grok过滤器覆盖生成的时间戳。

首先,我将使用grok过滤器,然后在结果上使用日期过滤器:

filter{
  grok{
    match=>{"message", "%{TIMESTAMP_ISO8601:DateTime} %{WORD:level} %{GREEDYDATA:message}"}
  }
  date{
    match=>["t","UNIX_MS"]
    target=>"timestamp"
  }
}

未测试日期过滤器,您可以检查此站点上的grok过滤器:

  

http://grokconstructor.appspot.com/do/match

'等级'在grok模式中不需要,可以随意将其删除。