How to remove fields with - values in logstash filter?

I have a patterns like :

  1. 2021-10-15 20:00:13 2396 tstur1 /ftp/workspace/ this is message
  2. 2020-10-15 18:00:13 - - this is the second message
    The fields are Date, Time, SessionId, path and message.
    The grok pattern used is :
    %{DATE:date} %{TIME:time} %{DATA:sessionid} %{DATA:username} %{DATA:path} %{GREEDYDATA:message}

is it possible to do a dynamic filter in logstash that will remove any fields with - value?

1 Like

Absolutely!
After your grok statement you can write an if statement.

if [sessionid] == "-" {
   mutate {
      remove_field => ["sessionid"]
   }
}
1 Like

Another possible solution is a prune filter with the blacklist_values options.

1 Like

thank you @AquaX for the help

thank you @Badger it worked

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.