Skip to main content

Append

Mutate Elastic Compatible

Synopsis

Appends one or more values to an array field.

Schema

append:
- description: <text>
- field: <ident>
- value: <any>
- allow_duplicates: <boolean>
- if: <script>
- ignore_failure: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- tag: <string>

Configuration

FieldRequiredDefaultDescription
fieldYField to append the value to
valueYThe value to be appended
allow_duplicatesNtrueIf false, only distinct values are appended
descriptionN-Explanatory notes
ifN-Condition to run
ignore_failureNfalseSee Handling Failures
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier

Details

If the field exists and is an array, the operation is carried out. If the field exists and is a scalar, the field is converted to an array before the operation. If the field doesn't exist, an array is created containing the provided values.

note

The append processor can be combined with foreach to append values from another array field.

Examples

Basic Usage

When appending to a non-existent field...

{
"name": "document1"
}
append:
- field: tags
- value: important

a new array is created:

{
"name": "document1",
"tags": ["important"]
}

Multiple Values

Multiple values can be appended at once...

{
"categories": ["books"]
}
append:
- field: categories
- value:
- magazines
- newspapers

which extends the existing array:

{
"categories": ["books", "magazines", "newspapers"]
}

Handling Duplicates

With allow_duplicates: false...

{
"tags": ["urgent", "important"]
}
append:
- field: tags
- value: important
- allow_duplicates: false

duplicate values are skipped:

{
"tags": ["urgent", "important"]
}

Converting Scalar to Array

When appending to a scalar field...

{
"status": "active"
}
append:
- field: status
- value: pending

it's automatically converted to an array:

{
"status": ["active", "pending"]
}

Using Templates

Template values can be used with mustache syntax...

{
"user_id": "12345",
"roles": ["user"]
}
append:
- field: roles
- value: "role_{{{user_id}}}"

which get evaluated during processing:

{
"user_id": "12345",
"roles": ["user", "role_12345"]
}