Keep First
Synopsis
Keeps first N characters of strings or N elements of arrays.
Schema
- keep_first:
field: <ident>
count: <integer>
target_field: <string>
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 |
---|---|---|---|
field | Y | - | Source field containing string or array to process |
count | Y | - | Number of characters/elements to keep from the beginning |
target_field | N | Same as field | Target field to store result |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if operation fails |
ignore_missing | N | false | Skip processing if referenced field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
Details
Extracts the first N characters from string values or the first N elements from array values. This processor is useful for truncating data, creating prefixes, or limiting the size of fields for analysis or display purposes.
The processor handles both string and array data types automatically, applying the appropriate logic based on the input type. For strings, it counts Unicode characters properly, and for arrays, it preserves the original data types of the elements.
When processing strings, the processor counts Unicode characters correctly, not bytes. This ensures proper handling of international characters and emojis.
If the specified count is greater than the length of the string or array, the processor returns the entire original value without modification.
Non-string and non-array values will cause the processor to fail unless ignore_failure
is set to true
. The processor cannot determine what "first N" means for other data types.
Examples
String Truncation
Keeping first 10 characters of a string... |
|
creates truncated preview: |
|
Array Limitation
Keeping first 3 elements from an array... |
|
keeps only first 3 elements: |
|
In-Place Truncation
Truncating field value in place... |
|
overwrites original field: |
|
Unicode String Handling
Properly handling Unicode characters... |
|
counts Unicode characters correctly: |
|
Conditional Processing
Applying truncation based on conditions... |
|
truncates when condition matches: |
|