Filebeat-控制级别如何嵌套JSON对象解析-Decode_json_fields

时间:2019-01-24 09:12:52

标签: elasticsearch filebeat

我如何控制decode_json_fields级别

max_depth对于我来说似乎无济于事。

目标:解析'/var/lib/docker/containers//.log'但控制最大json深度(不在Elasticsearch索引中生成数百个嵌套字段)

name: "host-01"
queue:
  mem:
    events: 16384
    # batch of events to the outputs. "0" ensures events are immediately available to be sent to the outputs.
    flush.min_events: 0


filebeat:
  prospectors:
    - type: log
      paths:
       - '/tmp/test.log'
      json:
        # key on which to apply the line filtering and multiline settings
        message_key: log
        keys_under_root: true
        add_error_key: true
      processors:
      - decode_json_fields:
          fields: ["log"]
          process_array: false
          max_depth: 1
          overwrite_keys: false

output:
  console:
    pretty: true

示例

echo '{"log":"{ "status": { "foo": { "bar": 1 } }, "bytes_sent": "0", "gzip_ratio": "-", "hostname": "cb7b5441f0da" }\n","stream":"stdout","time":"2018-12-29T11:25:36.130729806Z"}' >> /tmp/test.log

实际结果:

{
...
  "log": {
    "status": {
      "foo": {
        "bar": 1
      }
    },
    "bytes_sent": "0",
    "gzip_ratio": "-",
    "hostname": "cb7b5441f0da"
...
}

预期结果:

{
...
  "log": {
    "status": "{  \"foo\": { \"bar\": 1 } }"
   },
  "bytes_sent": "0",
  "gzip_ratio": "-",
  "hostname": "cb7b5441f0da"
...
}

如何控制嵌套的json对象?

以下是一些解释https://github.com/elastic/beats/issues/9834#issuecomment-451134008 1 但是删除json:仅保留decode_json_fields没有帮助

crosslink来讨论.elastic.co https://discuss.elastic.co/t/filebeat-how-control-level-nested-json-object-parsing-decode-json-fields/162876

0 个答案:

没有答案