如何使用流利的方式为弹性搜索添加时间戳和密钥

How to add timestamp & key for elasticsearch using fluent

我已经配置了 fluentd 和 elasticsearch,它们都运行良好。我正在跟踪一个文件,然后读取它的数据并将其发布到 elasticsearch。以下是 json 数据:

{"time": "2018-05-14T11:37:30.339593", "Data count": 78, "Data status": "Sent", "DataId": "332"}

下面是 fluentd 配置文件:

<source>
  @type tail
  time_key time
  path /home/user/file.json
  format json
  tag first
</source>

<match *first*>
  @type elasticsearch
  hosts 192.168.196.118:9200
  user <username>
  password <password>
  index_name myindex
  type_name mytype
  id_key 100
  time_key time
</match>

在上面的配置文件中,我添加了 time_key 因为时间是我想从 json 数据中使用的时间。但是我在 elasticsearch 中收到的数据不包含任何时间数据。

此外,我正在使用 id_key 但在 elasticsearch 中,id_key 是一些随机值。

请帮忙。谢谢

尝试注入你想要的值:

<inject>
   time_key          @log_time
   time_format       %Y%m%dT%H%M%S%z
</inject>

按照以下说明进行操作:https://docs.fluentd.org/v1.0/articles/inject-section

我解决了这个问题。我不必在配置文件中添加任何额外的东西。我只是在elasticsearch中选择时间作为时间字段。