Logstash - 更改克隆文档中字段的值(logstash-clone 过滤器插件)
Logstash - change value of field in cloned document (logstash-clone filter plugin)
Logstash 7.8.1
我正在尝试使用 logstash 从一个输入创建两个文档。不同的模板,不同的输出指标。一切正常,直到我尝试仅更改克隆文档上的值。
我需要在两个文档中有一个具有不同值的字段 - 是否可以使用克隆过滤器插件?
文档 A - [测试][事件]- trn
文档 B(克隆文档)- [测试][事件]- spn
我认为如果我在克隆插件中使用 remove_field 和下一个 add_field 它会起作用,但我担心排序有问题 - 也许 remove_field 方法是在 add_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 }
}
}
如果您想让添加的字段以事件是克隆事件还是原始事件为条件,请检查 [type] 字段。
clone { clones => ["cloned"] }
if [type] == "cloned" {
mutate { add_field => { "foo" => "spn" } }
} else {
mutate { add_field => { "foo" => "trn" } }
}
add_field 总是 done 在 remove_field 之前。
Logstash 7.8.1
我正在尝试使用 logstash 从一个输入创建两个文档。不同的模板,不同的输出指标。一切正常,直到我尝试仅更改克隆文档上的值。 我需要在两个文档中有一个具有不同值的字段 - 是否可以使用克隆过滤器插件?
文档 A - [测试][事件]- trn
文档 B(克隆文档)- [测试][事件]- spn
我认为如果我在克隆插件中使用 remove_field 和下一个 add_field 它会起作用,但我担心排序有问题 - 也许 remove_field 方法是在 add_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 }
}
}
如果您想让添加的字段以事件是克隆事件还是原始事件为条件,请检查 [type] 字段。
clone { clones => ["cloned"] }
if [type] == "cloned" {
mutate { add_field => { "foo" => "spn" } }
} else {
mutate { add_field => { "foo" => "trn" } }
}
add_field 总是 done 在 remove_field 之前。