Reputation: 10474
We want to filter a log using Logstash by removing fields if the field does not contain "_log". The remove_field
syntax is available, but only works for removing a field if it matches a certain condition.
filter {
grok {
remove_field => [ "log_" ]
}
}
# This works for removing the log_ field, we want to remove everything that does NOT match log_.
Is it also possible to remove a field if it does not match a certain condition?
We tried using a regex that did just that, but that did not work (is it documented somewhere that you cannot use a regex?). Removing all other fields is also an option, but way more effort. We hope someone can help us fitering all fields that do not contain "log_".
Upvotes: 1
Views: 4788
Reputation: 16362
The regexp should work:
filter {
if [field] !~ /pattern/ {
mutate {
remove_field => [ "field" ]
}
}
}
Upvotes: 5
Reputation: 13640
One of the ways you can do it is..
tag_on_failure
)Example:-
grok {
match => ["log_"]
tag_on_failure => ["_todelete"]
}
and then
grok {
remove_tag => [ "_todelete" ]
}
Upvotes: 4