【问题标题】:How to add timestamp & key for elasticsearch using fluent如何使用流利的为弹性搜索添加时间戳和密钥
【发布时间】:2018-05-14 11:42:53
【问题描述】:

我已经配置了 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,但在弹性搜索中,id_key 是一些随机值。

请帮忙。谢谢

【问题讨论】:

    标签: elasticsearch logging fluentd


    【解决方案1】:

    尝试注入你想要的值:

    <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 插件支持此功能?
    【解决方案2】:

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

    【讨论】:

    猜你喜欢
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    相关资源
    最近更新 更多