如何在 Fluentd 中扩展 JSON?

How to expand JSON in Fluentd?

有没有办法在 fluentd 中将嵌套的 JSON 字符串过滤到单独的字段中?

当前 JSON:

 { 
   Value1: "something",
   Value2: "something",
   Message:{
             Value3: "Something",
             Value3: "Something"
          }
 }

我想要的(或类似的东西):

 { 
   Value1: "something",
   Value2: "something",
   Message.Value3: "Something",
   Message.Value3: "Something"
          
 }

JSON 不必像上面的示例那样展平,但我确实希望这些值在到达 elasticsearch 时位于它们自己单独的字段(列)中。另一方面,我想将单个长消息字符串拆分为包含在其中的多个字段。

试试这个:

<source>
...
</source>

<filter myapp**>
  @type parser
  key_name Message

  format multi_format
  <pattern>
    format json # try parsing json in the first place
  </pattern>
  <pattern>
    format none # leave as is if this is not json (plaintext)
  </pattern>

  reserve_data true # keep the original Message field in case anything go wrong
</filter>

<match myapp**>
...
</match>

Multi-format 解析器:https://github.com/repeatedly/fluent-plugin-multi-format-parser