【问题标题】:Logstash - change value of field in cloned document (logstash-clone filter plugin)Logstash - 更改克隆文档中字段的值(logstash-clone 过滤器插件)
【发布时间】:2020-11-06 15:35:32
【问题描述】:

Logstash 7.8.1

我正在尝试使用 logstash 从一个输入创建两个文档。不同的模板,不同的输出索引。一切正常,直到我尝试仅更改克隆文档的值。 我需要两个文档中的一个字段具有不同的值 - 是否可以使用克隆过滤器插件?

Doc A - [test][event]- trn

Doc B(克隆文档)- [test][event]- spn

我认为如果我在克隆插件中使用 remove_field 和 next add_field 它将起作用,但我担心排序有问题 - 可能在 add_field 之后调用 remove_field 方法(该字段仅被删除,但没有添加新值)。

接下来,我尝试先向克隆文档添加值,然后再向原始文档添加值,但它总是创建一个包含两个值(原始值和克隆值)的数组,并且我只需要在该字段中有一个值:/. 有人可以帮帮我吗?

配置:

input {

 file {
        path => "/opt/test.log"
        start_position => beginning
    }
}



filter {
  grok {
    match => {"message" => "... grok...."
       }
  }

mutate {
add_field => {"[test][event]" => "trn"}
}

clone {  
clones => ["cloned"] 
#remove_field => [ "[test][event]" ]  #remove the field completely
add_field => {"[test][event]" => "spn"}   #not added 
add_tag => [ "spn" ]
 }

}

output {
if "spn" in [tags] {
 elasticsearch {
    index => "spn-%{+yyyy.MM}"
    hosts => ["localhost:9200"]
    template_name => "templ1"
   }
  stdout { codec => rubydebug }
} else {
  elasticsearch {
    index => "trn-%{+yyyy.MM}"
    hosts => ["localhost:9200"]
    template_name => "templ2"
   }
  stdout { codec => rubydebug }
}
}

【问题讨论】:

    标签: logstash logstash-configuration


    【解决方案1】:

    如果您想让添加的字段以事件是克隆还是原始事件为条件,请检查 [type] 字段。

        clone {  clones => ["cloned"] }
        if [type] == "cloned" {
            mutate { add_field => { "foo" => "spn" } }
        } else {
            mutate { add_field => { "foo" => "trn" } }
        }
    

    add_field 在 remove_field 之前总是 done

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多