Generic Functions
Set
The Set function sets a field value to a literal value or a value retrieved from another field in the event.
Usage
- Operates On: Field values
- Supported Field Types: any
- Label: Optional
- Filter: Optional
Required Configuration
- Field Name: The path to the field name to set. If the path does not exist it will be created, along with any parent fields in the event. See the Usage Notes below for more details and limitations.
- Field Value: literal, type: string, int, double, bool or selector. If a selector is used its path must be surrounded by
{}
. The selected value and its children will be cloned and copied to the set target location.
Usage Notes
As noted above, if the path specified in Field Name does not exist in the event, it will be created along with any parent fields. However, there are a few exceptions to keep in mind.
- If the path results in a type change of a predecessor the set operation will not be performed.
- The set operation attempts to set a value on an array index that is out of bounds.
- The set operation attempts to create a new array with an index > 0.
For example, given the following sample event fragment the following set operations would fail with these specified field names.
{
"context": {
"data": [
{
"value": 0
}
]
}
}
- Field Name:
context.data.value
- Fails due to limitation 1, because it would changecontext.data
from an array to a map. - Field Name:
context.data[1]
- Fails due to limitation 2, because the index is out of bound. - Field Name:
context.new_data[100]
- Fails due to limitation 3. A new array cannot be created with index > 0.
Example
Set the field named environment
with the field value selected from {context.env}
Configuration
- Field Name:
environment
- Field Value:
{context.env}
Before
{
"context": {
"env": "staging"
}
}
After
{
"environment": "staging",
"context": {
"env": "staging"
}
}