Grok
Synopsis
Extracts structured fields from unstructured log messages using predefined patterns.
Schema
grok:
- field: <ident>
- patterns: <string[]>
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- ignore_missing: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- pattern_definitions: <map>
- tag: <string>
- trace_match: <boolean>
Configuration
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Text field to extract patterns from |
patterns | Y | - | List of patterns to try matching (first match wins) |
description | N | - | Documentation note |
if | N | - | Conditional expression |
ignore_failure | N | false | Skip pattern match failures |
ignore_missing | N | false | Skip if input field missing |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
pattern_definitions | N | - | Custom pattern definitions |
tag | N | - | Identifier for logging |
trace_match | N | false | Track which pattern matched |
Details
The Grok processor combines pre-defined patterns to match and extract values from text fields. It uses a pattern syntax that combines pattern names with field names in the format %{PATTERN_NAME:FIELD_NAME}
.
The processor provides type conversion by appending :type
to field names, e.g. %{NUMBER:duration:int}
. It supports two types of conversion:
Integer ( :int ) | Converts matched values to 32-bit integers |
Long ( :long ) | Converts matched values to 64-bit integers |
Pattern matching stops at the first successful match. Order your patterns from most specific to most general.
Complex patterns may impact performance. Monitor matching time, and consider optimizing patterns for frequently processed fields.
Examples
Basic
Parsing an Apache log entry... |
|
extracts structured fields: |
|
Custom Patterns
Defining and using custom patterns... |
|
creates structured output: |
|
Conversion
Converting matched values to specific types... |
|
is automatically handled: |
|
Syslog Parsing
Parsing a structured syslog message... |
|
extracts the syslog fields: |
|
Multiple Patterns
Trying multiple patterns in turn... |
|
where the first matches: |
|