Skip to main content

Trim

Mutate Elastic Compatible

Synopsis

Removes leading and trailing whitespace from string values.

Schema

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

Configuration

FieldRequiredDefaultDescription
fieldY-Field containing string(s) to trim
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
target_fieldNfieldField to store the trimmed value(s)

Details

The processor can handle both single string fields and arrays of strings. When processing an array, it trims each element.

warning

If the field contains non-string values, the processor will fail unless ignore_failure is set to true.

note

The processor only removes whitespace characters (spaces, tabs, and new lines) from the beginning and end of strings. It does not affect whitespace between words.

Examples

Single String

Trimming the username...

{
"myusername": " username "
}
trim:
- field: myusername

removes the leading and trailing spaces:

{
"myusername": "username"
}

String Arrays

Trimming an array of email addresses...

{
"myemails": [
" [email protected] ",
" [email protected] "
]
}
trim:
- field: myemails

removes leading and trailing spaces from each:

{
"myemails": [
"[email protected]",
"[email protected]"
]
}

Target Field

Storing the trimmed values in a new field...

{
"original": " value "
}
trim:
- field: original
- target_field: trimmed

preserves the original:

{
"original": " value ",
"trimmed": "value"
}