Select
Synopsis
An array processing processor that extracts a specific element from arrays by position, supporting both positive and negative indexing for flexible element selection from various array types including strings, integers, floats, and booleans.
Schema
- select:
field: <ident>
position: <string>
target_field: <ident>
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 | - | Field containing the array to process |
position | Y | - | Position of element to select (0-based index) |
target_field | Y | - | Field to store the selected element |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue if selection fails |
ignore_missing | N | false | Continue if source field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
Details
The processor supports multiple array types including string arrays, interface arrays, integer arrays, float arrays, and boolean arrays. Position indexing is zero-based with support for negative indices to count from the end of the array.
Negative indices allow selection from the end of arrays, where -1 represents the last element, -2 the second-to-last, and so on.
Array bounds checking ensures safe element access, returning errors for out-of-bounds positions rather than causing runtime panics. The processor validates that the target field is specified since element selection requires a destination.
Position validation ensures that the provided position is a valid integer value, supporting both positive and negative indexing for comprehensive array element access.
The target_field parameter is required and must be specified to store the selected element.
Examples
First Elements
Selecting the first element from an array... |
|
extracts the first elements: |
|
Last Elements
Using negative indexing to select the last element... |
|
extracts the last elements: |
|
Middle Elements
Selecting elements from the middle of arrays... |
|
extracts middle elements: |
|
Boolean Arrays
Selecting from boolean arrays... |
|
extracts boolean values: |
|
Multiple
Selecting multiple elements from the same array... |
|
extracts multiple components: |
|
Conditional
Selecting elements based on conditions... |
|
applies selection when condition matches: |
|