elasticsearch 在Logstash if语句中使用非白名单字段
我有一个logstash配置,在这里我使用prune来白名单几个字段elasticsearch 在Logstash if语句中使用非白名单字段,elasticsearch,logstash,kibana,elasticsearch,Logstash,Kibana,我有一个logstash配置,在这里我使用prune来白名单几个字段 prune { whitelist_names => ["id","name"] } 问题是,我需要在id字段以外的字段的输出中使用if条件,例如:“type”。但由于我没有将“类型”列入白名单,if条件不起作用 if ( [type] in ["abc","efg"] ) { elasticsearch {
prune {
whitelist_names => ["id","name"]
}
问题是,我需要在id字段以外的字段的输出中使用if条件,例如:“type”。但由于我没有将“类型”列入白名单,if条件不起作用
if ( [type] in ["abc","efg"] ) {
elasticsearch {
action => "update"
hosts => [ "localhost:9200" ]
index => "index"
document_id => "%{id}"
doc_as_upsert => true
}
}
如何在if条件下使用非白名单字段?在修剪过滤器之前,添加一个变异过滤器,将要删除的字段的值(
键入
)复制到一个新的元数据字段中。然后,修剪。然后,在输出条件中使用新的元数据字段
...
filter {
...
mutate {
add_field => {
"[@metadata][type]" => "%{type}"
}
}
prune {
whitelist_names => ["id","name"]
}
...
}
output {
if [@metadata][type] in ["abc","efg"] {
elasticsearch {
action => "update"
hosts => [ "localhost:9200" ]
index => "index"
document_id => "%{id}"
doc_as_upsert => true
}
}
}
在修剪过滤器之前,添加一个变异过滤器,将要删除的字段的值(
type
)复制到一个新的元数据字段中。然后,修剪。然后,在输出条件中使用新的元数据字段
...
filter {
...
mutate {
add_field => {
"[@metadata][type]" => "%{type}"
}
}
prune {
whitelist_names => ["id","name"]
}
...
}
output {
if [@metadata][type] in ["abc","efg"] {
elasticsearch {
action => "update"
hosts => [ "localhost:9200" ]
index => "index"
document_id => "%{id}"
doc_as_upsert => true
}
}
}
工作得很有魅力!谢谢:)工作得很有魅力!谢谢:)