For other versions, see theVersioned plugin docs.
For questions about the plugin, open a topic in the Discuss forums. For bugs or feature requests, open an issue in Github.For the list of Elastic supported plugins, please consult the Elastic Support Matrix.
This filter helps automatically parse messages (or specific event fields)which are of the foo=bar
variety.
For example, if you have a log message which contains ip=1.2.3.4error=REFUSED
, you can parse those automatically by configuring:
filter { kv { }}
The above will result in a message of ip=1.2.3.4 error=REFUSED
havingthe fields:
ip: 1.2.3.4
error: REFUSED
This is great for postfix, iptables, and other types of logs thattend towards key=value
syntax.
You can configure any arbitrary strings to split your data on,in case your data is not structured using =
signs and whitespace.For example, this filter can also be used to parse query parameters likefoo=bar&baz=fizz
by setting the field_split
parameter to &
.
This plugin supports the following configuration options plus the Common Options described later.
Setting | Input type | Required |
---|---|---|
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
string, one of |
No |
|
string, one of |
No |
|
No |
||
No |
||
No |
||
No |
||
string, one of |
No |
Also see Common Options for a list of options supported by allfilter plugins.
true
A bool option for removing duplicate key/value pairs. When set to false, onlyone unique key/value pair will be preserved.
For example, consider a source like from=me from=me
. [from]
will map toan Array with two elements: ["me", "me"]
. To only keep unique key/value pairs,you could use this configuration:
filter { kv { allow_duplicate_values => false }}
{}
A hash specifying the default keys and their values which should be added to the eventin case these keys do not exist in the source field being parsed.
filter { kv { default_keys => [ "from", "logstash@example.com", "to", "default@dev.null" ] }}
[]
An array specifying the parsed keys which should not be added to the event.By default no keys will be excluded.
For example, consider a source like Hey, from=<abc>, to=def foo=bar
.To exclude from
and to
, but retain the foo
key, you could use this configuration:
filter { kv { exclude_keys => [ "from", "to" ] }}
" "
A string of characters to use as single-character field delimiters for parsing out key-value pairs.
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
## Example with URL Query Strings
For example, to split out the args from a url query string such as?pin=12345~0&d=123&e=foo@bar.com&oq=bobo&ss=12345
:
filter { kv { field_split => "&?" }}
The above splits on both &
and ?
characters, giving you the followingfields:
pin: 12345~0
d: 123
e: foo@bar.com
oq: bobo
ss: 12345
A regex expression to use as field delimiter for parsing out key-value pairs.Useful to define multi-character field delimiters.Setting the field_split_pattern
options will take precedence over the field_split
option.
Note that you should avoid using captured groups in your regex and you should becautious with lookaheads or lookbehinds and positional anchors.
For example, to split fields on a repetition of one or more colonsk1=v1:k2=v2::k3=v3:::k4=v4
:
filter { kv { field_split_pattern => ":+" } }
To split fields on a regex character that need escaping like the plus signk1=v1++k2=v2++k3=v3++k4=v4
:
filter { kv { field_split_pattern => "\\+\\+" } }
true
A boolean specifying whether to treat square brackets, angle brackets,and parentheses as value "wrappers" that should be removed from the value.
filter { kv { include_brackets => true }}
For example, the result of this line:bracketsone=(hello world) bracketstwo=[hello world] bracketsthree=<hello world>
will be:
instead of:
[]
An array specifying the parsed keys which should be added to the event.By default all keys will be added.
For example, consider a source like Hey, from=<abc>, to=def foo=bar
.To include from
and to
, but exclude the foo
key, you could use this configuration:
filter { kv { include_keys => [ "from", "to" ] }}
""
A string to prepend to all of the extracted keys.
For example, to prepend arg_ to all keys:
filter { kv { prefix => "arg_" } }
false
A boolean specifying whether to drill down into valuesand recursively get more key-value pairs from it.The extra key-value pairs will be stored as subkeys of the root key.
Default is not to recursive values.
filter { kv { recursive => "true" }}
A string of characters to remove from the key.
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
Contrary to trim option, all characters are removed from the key, whatever their position.
For example, to remove <
>
[
]
and ,
characters from keys:
filter { kv { remove_char_key => "<>\[\]," }}
A string of characters to remove from the value.
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
Contrary to trim option, all characters are removed from the value, whatever their position.
For example, to remove <
, >
, [
, ]
and ,
characters from values:
filter { kv { remove_char_value => "<>\[\]," }}
"message"
The field to perform key=value
searching on
For example, to process the not_the_message
field:
filter { kv { source => "not_the_message" } }
The name of the container to put all of the key-value pairs into.
If this setting is omitted, fields will be written to the root of theevent, as individual fields.
For example, to place all keys into the event field kv:
filter { kv { target => "kv" } }
_kv_filter_error
.When a kv operation causes a runtime exception to be thrown within the plugin,the operation is safely aborted without crashing the plugin, and the event istagged with the provided value.
_kv_filter_timeout
.When timeouts are enabled and a kv operation is aborted, the event is taggedwith the provided value (see: timeout_millis
).
0
) to disable timeoutsTimeouts provide a safeguard against inputs that are pathological against theregular expressions that are used to extract key/value pairs. When parsing anevent exceeds this threshold the operation is aborted and the event is taggedin order to prevent the operation from blocking the pipeline(see: tag_on_timeout
).
lowercase
, uppercase
, capitalize
Transform keys to lower case, upper case or capitals.
For example, to lowercase all keys:
filter { kv { transform_key => "lowercase" }}
lowercase
, uppercase
, capitalize
Transform values to lower case, upper case or capitals.
For example, to capitalize all values:
filter { kv { transform_value => "capitalize" }}
A string of characters to trim from the key. This is useful if yourkeys are wrapped in brackets or start with space.
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
Only leading and trailing characters are trimed from the key.
For example, to trim <
>
[
]
and ,
characters from keys:
filter { kv { trim_key => "<>\[\]," }}
Constants used for transform checkA string of characters to trim from the value. This is useful if yourvalues are wrapped in brackets or are terminated with commas (like postfixlogs).
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
Only leading and trailing characters are trimed from the value.
For example, to trim <
, >
, [
, ]
and ,
characters from values:
filter { kv { trim_value => "<>\[\]," }}
"="
A non-empty string of characters to use as single-character value delimiters for parsing out key-value pairs.
These characters form a regex character class and thus you must escape special regexcharacters like [
or ]
using \
.
For example, to identify key-values such askey1:value1 key2:value2
:
filter { kv { value_split => ":" } }
A regex expression to use as value delimiter for parsing out key-value pairs.Useful to define multi-character value delimiters.Setting the value_split_pattern
options will take precedence over the value_split option
.
Note that you should avoid using captured groups in your regex and you should becautious with lookaheads or lookbehinds and positional anchors.
See field_split_pattern
for examples.
lenient
, strict
lenient
An option specifying whether to be lenient or strict with the acceptance of unnecessarywhitespace surrounding the configured value-split sequence.
By default the plugin is run in lenient
mode, which ignores spaces that occur before orafter the value-splitter. While this allows the plugin to make reasonable guesses with mostinput, in some situations it may be too lenient.
You may want to enable whitespace => strict
mode if you have control of the input data andcan guarantee that no extra spaces are added surrounding the pattern you have defined forsplitting values. Doing so will ensure that a field-splitter sequence immediately followinga value-splitter will be interpreted as an empty field.
The following configuration options are supported by all filter plugins:
Setting | Input type | Required |
---|---|---|
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
{}
If this filter is successful, add any arbitrary fields to this event.Field names can be dynamic and include parts of the event using the %{field}
.
Example:
filter { kv { add_field => { "foo_%{somefield}" => "Hello world, from %{host}" } }}
# You can also add multiple fields at once:filter { kv { add_field => { "foo_%{somefield}" => "Hello world, from %{host}" "new_field" => "new_static_value" } }}
If the event has field "somefield" == "hello"
this filter, on success,would add field foo_hello
if it is present, with thevalue above and the %{host}
piece replaced with that value from theevent. The second example would also add a hardcoded field.
[]
If this filter is successful, add arbitrary tags to the event.Tags can be dynamic and include parts of the event using the %{field}
syntax.
Example:
filter { kv { add_tag => [ "foo_%{somefield}" ] }}
# You can also add multiple tags at once:filter { kv { add_tag => [ "foo_%{somefield}", "taggedy_tag"] }}
If the event has field "somefield" == "hello"
this filter, on success,would add a tag foo_hello
(and the second example would of course add a taggedy_tag
tag).
true
Disable or enable metric logging for this specific plugin instanceby default we record all the metrics we can, but you can disable metrics collectionfor a specific plugin.
Add a unique ID
to the plugin configuration. If no ID is specified, Logstash will generate one.It is strongly recommended to set this ID in your configuration. This is particularly usefulwhen you have two or more plugins of the same type, for example, if you have 2 kv filters.Adding a named ID in this case will help in monitoring Logstash when using the monitoring APIs.
filter { kv { id => "ABC" }}
false
Call the filter flush method at regular interval.Optional.
[]
If this filter is successful, remove arbitrary fields from this event.Example:
filter { kv { remove_field => [ "foo_%{somefield}" ] }}
# You can also remove multiple fields at once:filter { kv { remove_field => [ "foo_%{somefield}", "my_extraneous_field" ] }}
If the event has field "somefield" == "hello"
this filter, on success,would remove the field with name foo_hello
if it is present. The secondexample would remove an additional, non-dynamic field.
[]
If this filter is successful, remove arbitrary tags from the event.Tags can be dynamic and include parts of the event using the %{field}
syntax.
Example:
filter { kv { remove_tag => [ "foo_%{somefield}" ] }}
# You can also remove multiple tags at once:filter { kv { remove_tag => [ "foo_%{somefield}", "sad_unwanted_tag"] }}
If the event has field "somefield" == "hello"
this filter, on success,would remove the tag foo_hello
if it is present. The second examplewould remove a sad, unwanted tag as well.