Coalesce
Returns the first non-null, non-empty value from a list of fields, similar to SQL COALESCE function.
Schema
- coalesce:
fields: <ident[]>
target_field: <ident>
ignore_empty_string: <boolean>
description: <text>
if: <script>
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 |
---|---|---|---|
fields | Y | - | Array of field names to check in order |
target_field | Y | - | Target field to store the first non-null value |
ignore_empty_string | N | false | Skip empty strings when finding first value |
description | N | - | Explanatory note |
if | N | - | Condition to run processor |
ignore_failure | N | false | Continue if processor fails |
ignore_missing | N | false | Continue if all fields are missing |
on_failure | N | - | Processors to run on failure |
on_success | N | - | Processors to run on success |
tag | N | - | Processor identifier |
Details
The processor skips null
values automatically and by default treats empty strings as valid values, though this can be changed using ignore_empty_string: true
to skip them as well. Fields are evaluated in the order specified in the array, with missing fields automatically skipped.
The processor preserves the original data type of the selected value and fails if all fields are missing or empty unless ignore_missing: true
is configured.
This processor is particularly useful for field prioritization when multiple options are available, providing fallback values when primary fields might be missing. It excels at data consolidation by merging similar fields from different log sources, such as finding the best contact email from multiple possibilities or choosing the most appropriate client IP from various network fields.
The processor also helps with message standardization by selecting the best message field from different formats across diverse log sources.
Examples
Basic Usage
Finding first non-null value from user fields... |
|
selects first available value: |
|
Email Fallback
Default behavior treats empty strings as valid values... |
|
returns first value (empty string): |
|
Empty Strings
Using |
|
skips empty string, finds next value: |
|
IP Resolution
Selecting best available IP address from multiple sources... |
|
skips null/empty, finds first valid IP: |
|
Message Fallback
Finding message from various log format fields... |
|
selects first available message: |
|
Timestamps
Selecting best timestamp from multiple time fields... |
|
chooses first non-null timestamp: |
|