如何构建添加到logstash事件的字段?

时间:2016-08-03 21:58:14

标签: logstash logstash-grok

在Logstash中我正在使用grok将日志行解析为具有扁平结构的事件。

例如:

{
location_file_name: "ServiceDao.java"
location_line_number: 47
thread_name: "main-thread"
thread_number: "3"
}

我怎样才能将其解析为:

{
location : {
    file: "ServiceDao"
    line: 47
}
thread : {
    name: "main-thread"
    number: "3"
}
}

1 个答案:

答案 0 :(得分:1)

浏览完您的数据后,您可以使用mutate过滤器按照您的意愿重新组织字段:

filter {
    grok {
       ...
    }
    mutate {
       add_field => {
           "[location][file]" => "%{location_file_name}"
           "[location][line]" => "%{location_line_number}"
           "[thread][name]" => "%{thread_name}"
           "[thread][number]" => "%{thread_number}"
       }
       remove_field => ["location_file_name", "location_line_number", "thread_name", "thread_number"]
    }
}