The retain
operator keeps the specified list of fields, and removes the rest.
Field | Default | Description |
---|---|---|
id |
retain |
A unique identifier for the operator. |
output |
Next in pipeline | The connected operator(s) that will receive all outbound entries. |
fields |
required | A list of fields to be kept. |
on_error |
send |
The behavior of the operator if it encounters an error. See on_error. |
if |
An expression that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. |
NOTE: If no fields in a group (attributes, resource, or body) are specified, that entire group will be retained.
Retain fields in the body
- type: retain
fields:
- body.key1
- body.key2
Input Entry | Output Entry |
{
"resource": { },
"attributes": { },
"body": {
"key1": "val1",
"key2": "val2",
"key3": "val3",
"key4": "val4"
}
} |
{
"resource": { },
"attributes": { },
"body": {
"key1": "val1",
"key2": "val2"
}
} |
Retain an object in the body
- type: retain
fields:
- body.object
Input record | Output record |
{
"resource": { },
"attributes": { },
"body": {
"key1": "val1",
"object": {
"nestedkey": "val2",
}
}
} |
{
"resource": { },
"attributes": { },
"body": {
"object": {
"nestedkey": "val2",
}
}
} |
Retain fields from resource
- type: retain
fields:
- resource.key1
- resource.key2
Input record | Output record |
{
"resource": {
"key1": "val1",
"key2": "val2",
"key3": "val3"
},
"attributes": { },
"body": {
"key1": "val1",
}
}
} |
{
"resource": {
"key1": "val1",
"key2": "val2",
},
"attributes": { },
"body": {
"key1": "val1",
}
} |
Retain fields from attributes
- type: retain
fields:
- attributes.key1
- attributes.key2
Input record | Output record |
{
"resource": { },
"attributes": {
"key1": "val1",
"key2": "val2",
"key3": "val3"
},
"body": {
"key1": "val1",
}
} |
{
"resource": { },
"attributes": {
"key1": "val1",
"key2": "val2",
},
"body": {
"key1": "val1",
}
} |
Retain fields from all sources
- type: retain
fields:
- resource.key1
- attributes.key3
- body.key5
Input record | Output record |
{
"resource": {
"key1": "val1",
"key2": "val2"
},
"attributes": {
"key3": "val3",
"key4": "val4"
},
"body": {
"key5": "val5",
"key6": "val6",
}
} |
{
"resource": {
"key1": "val1",
},
"attributes": {
"key3": "val3",
},
"body": {
"key5": "val5",
}
} |