Sort
Synopsis
Sorts the elements of an array in ascending or descending order.
Schema
sort:
- field: <ident>
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- order: <enum>
- tag: <string>
- target_field: <ident>
Configuration
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Field containing the array to be sorted |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | See Handling Failures |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
order | N | asc | Sort order: asc or desc |
tag | N | - | Identifier |
target_field | N | field | Field to store the sorted array |
Details
Arrays of numbers will be sorted numerically, whereas string arrays will be sorted lexicographically. When dealing with mixed arrays containing both strings and numbers, the sorting is performed lexicographically.
The processor raises an exception if the specified field is not an array.
warning
The processor will fail if the specified field does not exist or is not an array. Set ignore_failure
to true
to handle such cases.
Examples
String Arrays
Sorting a string array in ascending order... |
|
orders strings lexicographically: |
|
Numeric Arrays
Sorting numeric arrays in ascending order... |
|
orders numbers numerically: |
|
Target Field
Sorting the array into a new field... |
|
preserves the original array: |
|