Logstash add_field 参数应用

使用 add_field 参数有两种需求:

1. 直接加入到 event 的 hash 顶级对象中

add_field => {
          "my_field_one" => "one"
}

那么,结果会类似:

复制代码
{
           "公司名称" => "xxx",
           "BUG_ID" => 1234,
           "VIP_Level" => "核心VIP",
           "my_field_one" => "one",
}
复制代码

2. 加入到 event 的某个 tag 中

 add_field => {
          "[其它][tag1]" => "one"
          "[其它][tag2]" => "two"
}

那么,结果会类似:

复制代码
{
           "公司名称" => "xxx",
           "BUG_ID" => 1234,
           "VIP_Level" => "核心VIP",
           "其它" => {
                   "tag1" => "one",
                   "tag2" => "two"
          }
}
复制代码

3. 由于 add_field 参数要求格式为 hash,我尝试如下用法结果发现满足不了需求。( ╯□╰ )为嘛???

复制代码
add_field => {
#方法一:
          "其它" => { "tag1" => "one",
                      "tag2" => "two"
                    }
#方法二:和logstash中一贯用法一样,不加逗号 "其它2" => { "tag1" => "one" "tag2" => "two" }
#方法三:写在一行上 "其它2" => {"tag1" => "one", "tag2" => "two" } }

#方法四:先执行 add_tag 再执行 add_field。这样为嘛会是数组???
add_tag => "其它" add_field = { "其它" => { "tag1" => "one" "tag2" => "two" } }

posted on 2019-11-29 16:30  ExplorerMan  阅读(6099)  评论(0编辑  收藏  举报

导航