使用logstash 从mysql取一个datetime类型的数字。 在stdout查看数据json格式取到的字段值为类似 2018-03-23T04:18:33.000Z,因为想使用这个字段作为@timestamp,所以使用logstash的date 去match 。

    date {
      match => ["start_time","ISO8601"]
    }

但实际发现每个document都会附带一个[_dataparserfail]的标签,百思不得姐 google一番后终于明白了,链接:https://discuss.elastic.co/t/trouble-matching-timestamp/83768/4

因为从mysql取到数据的时候start_time 已经是一个时间的数据类型了, 这时候再用date去处理自然失败,如果想使用这个字段作为@timestamp ,老外给的解决方法如下: In your SQL query, typecast the timestamp as a string. Use a mutate filter's convert option to typecast the field to a string prior to the date filter. Use a mutate filter to copy the timestamp into @timestamp and overwrite the existing value (use the replace option).

我使用的方法:

    mutate {
      add_field => {"temp_ts" => "%{start_time}"}
    }
    date {
      match => ["temp_ts","ISO8601"]
      remove_field => ["temp_ts"]
    }