## `Retain` operator The `retain` operator keeps the specified list of fields, and removes the rest. ### Configuration Fields | 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](/docs/types/field.md) to be kept. | | `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md) | | `if` | | An [expression](/docs/types/expression.md) 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. |
| Input Entry | Output Entry |
| ```json { "resource": { }, "labels": { }, "record": { "key1": "val1", "key2": "val2", "key3": "val3", "key4": "val4" } } ``` | ```json { "resource": { }, "labels": { }, "record": { "key1": "val1", "key2": "val2" } } ``` |
| Input entry | Output entry |
| ```json { "resource": { }, "labels": { }, "record": { "key1": "val1", "object": { "nestedkey": "val2", } } } ``` | ```json { "resource": { }, "labels": { }, "record": { "object": { "nestedkey": "val2", } } } ``` |
| Input entry | Output entry |
| ```json { "resource": { "key1": "val1", "key2": "val2", "key3": "val3" }, "labels": { }, "record": { "key1": "val1", } } } ``` | ```json { "resource": { "key1": "val1", "key2": "val2", }, "labels": { }, "record": { "key1": "val1", } } ``` |
| Input entry | Output entry |
| ```json { "resource": { }, "labels": { "key1": "val1", "key2": "val2", "key3": "val3" }, "record": { "key1": "val1", } } ``` | ```json { "resource": { }, "labels": { "key1": "val1", "key2": "val2", }, "record": { "key1": "val1", } } ``` |
| Input entry | Output entry |
| ```json { "resource": { "key1": "val1", "key2": "val2" }, "labels": { "key3": "val3", "key4": "val4" }, "record": { "key5": "val5", "key6": "val6", } } ``` | ```json { "resource": { "key1": "val1", }, "labels": { "key3": "val3", }, "record": { "key5": "val5", } } ``` |