简体   繁体   中英

Configuring Logstash to only include certain fields

Using filter , mutate , and remove_field , Logstash con be configured to exclude certain fields from the output.

But what if one only knows the names of the fields to be included, and wants to exclude all other fields (the names of which one did not know up front). How could this be done?

Thanks

You can use a ruby filter :

filter {
  ruby {
    code => "
      wanted_fields = ['message', 'foo']
      event.to_hash.keys.each { |k|
        event.remove(k) unless wanted_fields.include? k
      }
    "
  }
}

Related:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM