There are some basic options supported by all Logstash filter plugins that I often use to enrich the data.
For example, we can add a new field, remove an existing field, and more.
This tutorial will show you how to do that. Let's get started!
Contents
7 Common Options in Logstash Filter Plugins
There are 7 options that are supported by all Logstash filter plugins, which means you can use them in any filter plugin.
In this tutorial, I will use the mutate filter plugin as an example, you can use any filter plugin based on your needs.
I will also use the following sample data for demonstration throughout this tutorial:
For the input
and output
part of the filter config, I will use this config to parse JSON lines log:
1. add_field
In Logstash, the add_field action is used to add a new field to the event.
- Value type: hash
- Default value: {}
The syntax to add a single field is as follows:
To add multiple fields:
For example, we can add a new field fine
with the value true
to the event:
Using the above config will yield the result:
2. remove_field
To remove a field from the event in Logstash, we can use the remove_field action.
- Value type: array
- Default value: []
The syntax is as follows:
To remove multiple fields:
For example, we can remove the status
field from the event:
Here is the result:
3. add_tag
The add_tag action is used to add a tag to the event.
- Value type: array
- Default value: []
The syntax is as follows:
To add multiple tags:
4. remove_tag
To remove a tag from the event, we can use the remove_tag action.
- Value type: array
- Default value: []
The syntax is as follows:
To remove multiple tags:
5. id
The id action is used to set the ID of the plugin configuration, which is useful when you need to identify multiple plugins of the same type.
- Value type: string
- Default value: no default value, automatically generated if not specified
The syntax is as follows:
6. enable_metric
The enable_metric action is used to enable or disable the metric collection for the plugin.
- Value type: boolean
- Default value: true
The syntax is as follows:
7. periodic_flush
The periodic_flush action is used to enable or disable periodic flush for the plugin.
- Value type: boolean
- Default value: false
The syntax is as follows:
Conclusion
In this tutorial, you have learned how to use 7 common options in all Logstash filter plugins.
These options are usually combined with other filter plugins to enrich the data. You can check the Related Posts section on the right to learn more about Logstash filter plugins.
Comments
aida
Apr 01, 2024
easy to understand