-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add doc for json_decode_fields processor #3110
Changes from 5 commits
2c3cd22
e88a740
a882528
a8862b8
e4c041f
667d4d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
[[filtering-and-enhancing-data]] | ||
== Filtering and Enhancing the Exported Data | ||
|
||
When your use case requires only a subset of the data exported by Filebeat or you need to add metadata, you can <<filebeat-filtering-overview,use Filebeat config options to filter the data>>, or you can <<defining-processors,define processors>>. | ||
Your use case might require only a subset of the data exported by Filebeat, or | ||
you might need to enhance the exported data (for example, by adding metadata). | ||
Filebeat provides a couple of options for filtering and enhancing exported | ||
data. You can: | ||
|
||
* <<filebeat-filtering-overview,Define filters at the prospector level>> to | ||
configure each prospector to include or exclude specific lines or files. | ||
* <<defining-processors,Define processors>> to configure global processing | ||
across all data exported by Filebeat. | ||
|
||
[float] | ||
[[filebeat-filtering-overview]] | ||
=== Filebeat Config Options for Filtering | ||
=== Filtering at the Prospector Level | ||
|
||
You can specify filtering options at the prospector level to configure which | ||
lines or files are included or excluded in the output. This allows you to | ||
specify different filtering criteria for each prospector. | ||
|
||
You can specify configuration options in the `filebeat` section of the config file to define regular expressions that | ||
match the lines you want to include and/or exclude from the output. The supported options are <<include-lines,`include_lines`>>, <<exclude-lines,`exclude_lines`>>, and <<exclude-files,`exclude_files`>>. | ||
You configure prospector-level filtering in the `filebeat.prospectors` section | ||
of the config file by specifying regular expressions that match the lines you | ||
want to include and/or exclude from the output. The supported options are | ||
<<include-lines,`include_lines`>>, <<exclude-lines,`exclude_lines`>>, and | ||
<<exclude-files,`exclude_files`>>. | ||
|
||
For example, you can use the `include_lines` option to export any lines that start with "ERR" or "WARN": | ||
For example, you can use the `include_lines` option to export any lines that | ||
start with "ERR" or "WARN": | ||
|
||
[source,yaml] | ||
------------------------------------------------------------------------------------- | ||
|
@@ -21,17 +37,23 @@ filebeat.prospectors: | |
include_lines: ["^ERR", "^WARN"] | ||
------------------------------------------------------------------------------------- | ||
|
||
The disadvantage of this approach is that you need to implement a configuration option for each filtering criteria that you need. | ||
The disadvantage of this approach is that you need to implement a | ||
configuration option for each filtering criteria that you need. | ||
|
||
See <<configuration-filebeat-options,Filebeat configuration options>> for more information about each option. | ||
See <<configuration-filebeat-options,Filebeat configuration options>> for more | ||
information about each option. | ||
|
||
[float] | ||
[[defining-processors]] | ||
=== Defining Processors | ||
|
||
include::../../libbeat/docs/processors.asciidoc[] | ||
|
||
For example, the following configuration drops all the DEBUG messages. | ||
[float] | ||
[[drop-event-example]] | ||
==== Drop Event Example | ||
|
||
The following configuration drops all the DEBUG messages. | ||
|
||
[source,yaml] | ||
----------------------------------------------------- | ||
|
@@ -53,4 +75,54 @@ processors: | |
source: "test" | ||
---------------- | ||
|
||
[float] | ||
[[decode-json-example]] | ||
==== Decode JSON Example | ||
|
||
In the following example, the fields exported by Filebeat include a | ||
field, `inner`, whose value is a JSON object encoded as a string: | ||
|
||
[source,json] | ||
----------------------------------------------------- | ||
{ "outer": "value", "inner": "{\"data\": \"value\"}" } | ||
----------------------------------------------------- | ||
|
||
The following configuration decodes the inner JSON object: | ||
|
||
[source,yaml] | ||
----------------------------------------------------- | ||
filebeat.prospectors: | ||
- paths: | ||
- input.json | ||
json.keys_under_root: true | ||
|
||
processors: | ||
- decode_json_fields: | ||
fields: ['inner'] | ||
|
||
output.console.pretty: true | ||
----------------------------------------------------- | ||
|
||
The resulting output looks something like this: | ||
|
||
["source","json",subs="attributes"] | ||
----------------------------------------------------- | ||
{ | ||
"@timestamp": "2016-12-06T17:38:11.541Z", | ||
"beat": { | ||
"hostname": "macbook13.local", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the hostname and name fields to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"name": "macbook13.local", | ||
"version": "{version}" | ||
}, | ||
"inner": { | ||
"data": "value" | ||
}, | ||
"input_type": "log", | ||
"offset": 55, | ||
"outer": "value", | ||
"source": "input.json", | ||
"type": "log" | ||
} | ||
----------------------------------------------------- | ||
|
||
See <<configuration-processors>> for more information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,7 @@ The supported actions are: | |
* <<drop-fields,`drop_fields`>> | ||
* <<drop-event,`drop_event`>> | ||
* <<add-cloud-metadata,`add_cloud_metadata`>> | ||
* <<decode-json-fields,`decode_json_fields`>> | ||
|
||
See <<exported-fields>> for the full list of possible fields. | ||
|
||
|
@@ -371,3 +372,23 @@ _GCE_ | |
} | ||
} | ||
-------------------------------------------------------------------------------- | ||
|
||
[[decode-json-fields]] | ||
===== decode_json_fields | ||
|
||
The `decode_json_fields` action decodes fields containing JSON strings and replaces the strings with valid JSON objects. | ||
|
||
[source,yaml] | ||
----------------------------------------------------- | ||
processors: | ||
- decode_json_fields: | ||
fields: ["field1", "field2", ...] | ||
process_array: false | ||
max_depth: 1 | ||
----------------------------------------------------- | ||
|
||
The `decode_json_fields` action has the following configuration settings: | ||
|
||
`fields`:: The fields containing JSON strings to decode. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dedemorton Can you please mark this processor as experimental for 5.1 so that we can fix these config parameters in the next release. They should be named differently in the code to be consistent (like |
||
`process_array`:: (Optional) A boolean that specifies whether to process arrays. The default is false. | ||
`max_depth`:: (Optional) The maximum parsing depth. The default is 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the ~80 char line wrap. 👍