Pattern
Synopsis
Extracts structured patterns from log messages, identifying key components and normalizing variable content.
Schema
- pattern:
field: <ident>
target_field: <ident>
description: <text>
if: <script>
custom_patterns: <map[string]string>
tokenize_all: <boolean>
tokenizer: <string>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Field containing the message to analyze |
target_field | N | field | Field to store pattern information |
description | N | - | Documentation note |
custom_patterns | N | - | Map of custom regex patterns to use |
tokenize_all | N | false | Use all built-in patterns for tokenization. Applies to the default tokenizer only |
tokenizer | N | default | How the processor finds a message's pattern: default or search. See Tokenizers |
if | N | - | Condition to run |
ignore_failure | N | false | See Handling Failures |
ignore_missing | N | false | If true, skip if field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
Details
The processor extracts a normalized representation of log messages by first removing numeric or other identifiable values, and then replacing the standard patterns with tokens in order to generate a consistent pattern representation. It uses the following patterns:
EMAIL | Email address format |
IP | IP address detection |
NUMBER | Numeric values |
PATH | File system paths |
TIMESTAMP | Date and time formats |
URL | Web URLs |
For each processed message, the processor generates a pattern string, a unique hash, and an identifier. It limits the pattern to 100 words, and requires words to be at least 2 characters long.
The processor may modify the input message to create a generalized pattern.
Long messages are truncated, and specific identifiers are replaced with generic tokens.
Tokenizers
tokenizer chooses how the processor finds a message's pattern:
default | The processor's own tokenizer, described above. Leaving the option out gives the same result |
search | The processor writes the same template that the patterns() function of Search finds for the message on its own. Search masks numbers, IP addresses, hex values, ids, times, URLs and emails. A path stays one word, with its variable parts masked. Use this when you want the patterns stored at ingestion to match the ones a Search query finds over the same messages. A query over many messages also groups similar templates, replacing a word that varies among them with <*>. The processor reads one message at a time and doesn't do this, so a stored pattern can still have a word where the query shows <*> |
- The default doesn't change. Switching an existing pipeline to
searchchanges the patterns it writes, and so theirhashandidvalues. Patterns stored before the switch won't match the new ones. custom_patternswork with both tokenizers. The processor applies them first.tokenize_allonly affects thedefaulttokenizer. Thesearchtokenizer always masks its token types.- The output is unchanged. The target field still gets
pattern,hashandid. - Any other value is refused with the error
tokenizer "x" is not supported: use default or search.
Examples
Basic
Extracting a pattern from a log message... | |
creates a normalized one: | |
Custom
Adding a custom pattern for error codes... | |
applies it: | |
Tokenizing
Using all built-in patterns... | |
replaces all the known patterns: | |
Search Tokenizer
Finding the pattern the way Search does... | |
writes the template Search's | |
For the same message, tokenize_all: true with the default tokenizer writes <TIMESTAMP> ERROR checkout-service failed to charge card for order <NUMBER> payment declined by issuer.
Error Handling
Handling non-string inputs... | |
adds an error tag and continues execution: | |