[英]change dynamic field value in logstash
I'm using a filter in logstash.我在logstash中使用过滤器。 I wanna change value of a dynamic field in logstash.
我想更改logstash中动态字段的值。 I'm using below codes in my filter:
我在过滤器中使用以下代码:
if [state_ls_keyvalue] == "False" {
mutate{
add_field => {"%{field_ls_keyvalue}" => "%{enrich_column}"}
}
} else {
mutate{
remove_field => ["%{field_ls_keyvalue}"]
}
mutate{
add_field => {"%{field_ls_keyvalue}" => "%{enrich_column}"}
}
}
but it does not work.但它不起作用。 how shall I handle it?
我该如何处理?
Both the remove_field and add_field sprintf the field name. remove_field和add_field sprintf 都是字段名称。
output { stdout { codec => rubydebug { metadata => false } } }
input { generator { count => 1 lines => [ '{ "field_ls_keyvalue": "a", "a": "c", "enrich_column": "d" }' ] codec => json { } } }
filter {
mutate { remove_field => [ "%{field_ls_keyvalue}" ] }
mutate { add_field => { "%{field_ls_keyvalue}" => "%{enrich_column}" } }
}
will produce会产生
"a" => "d",
If that is not happening for you then it suggests the conditional test of [validation] is evaluating to false.如果您没有发生这种情况,则表明 [validation] 的条件测试评估为假。
The problem is related to type of field in elasticsearch.该问题与弹性搜索中的字段类型有关。 we can handle with mapping and change it.
我们可以处理映射并更改它。
using only add_field
, the value of new field appends into old one.仅使用
add_field
,新字段的值会附加到旧字段中。
using remove_field
and then add_field
, replace the value of new field to old one.使用
remove_field
然后add_field
,将新字段的值替换为旧字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.