Grok
Synopsis
Extracts structured fields from unstructured log messages using predefined patterns.
Reusable grok patterns can be created and managed in the Library.
Schema
- grok:
field: <ident>
patterns: <string[]>
break_on_match: <boolean>
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
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Text field to extract patterns from |
patterns | Y | - | List of patterns to try matching. See below |
break_on_match | N | true | Stop at first matching pattern (true) or evaluate all patterns and merge captures (false) |
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 |
Built-in Patterns
| Category | Patterns |
|---|---|
| General | DATA GREEDYDATA NOTSPACE SPACE WORD |
| Numeric | BASE10NUM INT NUMBER |
| Networking | HOSTNAME IP IPV4 IPV6 MAC |
| Date and Time | DATESTAMP DATESTAMP_RFC822 TIMESTAMP_ISO8601 |
| File System | FILENAME PATH |
| HTTP | HTTPDATE HTTPDERRORLOG HTTPDUSER |
| System | SYSLOGBASE SYSLOGHOST SYSLOGTIMESTAMP |
| Other | EMAILADDRESS URIPARAM URIPATH UUID |
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 |
By default (break_on_match: true), pattern matching stops at the first successful match — order your patterns from most specific to most general. Set break_on_match: false to evaluate every pattern and merge captures from each successful match.
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
Defining and using custom patterns... | |
creates structured output: | |
Multiple
Trying multiple patterns in turn... | |
where the first matches: | |
Cumulative
Evaluating all patterns to capture multiple segments... | |
Every successful pattern contributes its captures: | |
Conversion
Converting matched values to specific types... | |
is automatically handled: | |
Parsing
Parsing a structured syslog message... | |
extracts the syslog fields: | |