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

How to structure the fields added to logstash events?

在 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"
}
}

搜索完数据后,您可以使用 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"]
    }
}