Gsub
Synopsis
Performs pattern-based string replacements using regular expressions.
Schema
gsub:
- field: <ident>
- pattern: <string>
- replacement: <string>
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- ignore_missing: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- tag: <string>
- target_field: <ident>
Configuration
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Source field containing text to modify |
pattern | Y | - | Regular expression pattern to match |
replacement | Y | - | Text or pattern to replace matches with |
description | N | - | Documentation note |
if | N | - | Conditional expression |
ignore_failure | N | false | Skip processing errors |
ignore_missing | N | false | Skip if input field missing |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
tag | N | - | Identifier for logging |
target_field | N | field | Output field for modified text |
Details
The processor supports both simple string replacements and complex regex patterns, with the ability to store results in the original field or a new target field.
The processor caches compiled regular expressions when dealing with multiple documents with the same pattern. Complex patterns are only compiled once and reused for subsequent matches.
Be careful with complex regular expressions on large text fields, as these may impact performance. Test patterns thoroughly, and consider using simpler patterns when possible.
Examples
Basic Replacement
Replacing error code in message... |
|
modifies original field: |
|
IP Address Anonymization
Anonymizing IP addresses in logs... |
|
replaces all: |
|
Keep Original
Storing the modified text in a new field... |
|
preserves the original field: |
|
Conditionals
Replacing based on criteria... |
|
executes the replacement conditionally: |
|
Error Handling
Handling missing fields gracefully... |
|
continues the execution: |
|