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
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 (first match wins). See below |
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 |
note
Pattern matching stops at the first successful match. Order your patterns from most specific to most general.
caution
Complex patterns may impact performance. Monitor matching time, and consider optimizing patterns for frequently processed fields.