如何在logstash中使用grok或gsub删除特定单词之前的部分字符串?

时间:2017-01-20 11:17:01

标签: elasticsearch logstash gsub logstash-grok grok

我有一个字符串字段" origin_message"。它非常大(使用多行来获取邮件内容。例如" origin_message":

Delivered-to: somemail@domain.com A LOT OF OTHER CONTENT Subject: Subject goes here AND THE REST OF THE MESSAGE

期望的结果:

Subject goes here AND THE REST OF THE MESSAGE

有没有办法在#34之前修剪一切;主题:"短语?

我尝试过以下过滤器但没有运气:

filter {
mutate {
    add_field => { "original_message" => "%{message}" }
    convert => {
        "original_message" => "string"
    }

    gsub => [
        "original_message", "^(.*)Subject", " "
    ]
}
}

1 个答案:

答案 0 :(得分:1)

不确定为什么,但在"消息"上使用gsub复制之前的字段以分隔" original_message"领域解决了这个问题。

filter {
mutate {
    gsub => ["message", "^(.*)Subject", " "]
    add_field => { "original_message" => "%{message}" }

    convert => {
        "original_message" => "string"
    }
}
}

@Val,谢谢你的验证。问题似乎与模式无关。