Skip to main content

Reverse

Mutate

Synopsis

Reverses the order of a field's contents: the characters of a string, or the elements of an array.

Schema

- reverse:
field: <ident>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
target_field: <ident>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Field to reverse. Must hold a string or an array
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseSee Handling Failures
ignore_missingNfalseIf true, quietly exit if field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration
target_fieldNfieldField to store the reversed value. Defaults to field, reversing in place

Details

A string is reversed by character, not by byte, so multi-byte text survives the operation intact. An array is reversed by element; the elements themselves are untouched, including nested objects and arrays.

Any other value — a number, an object, a boolean — is an error. There is no meaningful element order to reverse.

The reversed value is built as a new value rather than being rearranged in place, so a target_field that differs from field leaves the source exactly as it was.

Examples

Reversing a String

Reversing the characters of a string...

{
"domain": "example.com"
}
- reverse:
field: domain
target_field: domain_reversed

which is the form domain lookups often index on:

{
"domain": "example.com",
"domain_reversed": "moc.elpmaxe"
}

Reversing an Array

Reversing element order, newest event first...

{
"trace": ["dispatch", "validate", "receive"]
}
- reverse:
field: trace

in place, since no target_field was given:

{
"trace": ["receive", "validate", "dispatch"]
}

Non-ASCII Text

Reversal is by character, so accented and non-Latin text is not corrupted...

{
"label": "café"
}
- reverse:
field: label
target_field: label_reversed

and the accented character survives:

{
"label": "café",
"label_reversed": "éfac"
}