Compact
Synopsis
Removes null values, empty and whitespace-only strings, empty arrays, and empty objects recursively.
Schema
- compact:
values: <array>
excluded_fields: <array>
description: <text>
if: <script>
ignore_failure: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
values | N | - | Array of values to be removed when found, in addition to empty fields |
excluded_fields | N | - | Array of field names to exclude from compaction |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | See Handling Failures |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
Details
Empty fields include null values, empty strings, empty arrays [], and empty objects {}. This processor helps reduce the document size and improve readability by eliminating all the unnecessary fields.
A string of nothing but whitespace counts as empty. A field holding " " or a lone tab is dropped exactly as "" is, so a padded field that a parser left behind does not survive as a value that merely looks blank.
The processor is particularly useful for cleaning up documents before storage or transmission, reducing storage space and network bandwidth usage.
Examples
Basic
Remove empty fields from document... | |
resulting in only non-empty fields: | |
Nested Objects
Process nested objects recursively... | |
removing empty fields at all levels: | |
Specific Values
Remove empty fields and... | |
specific values: | |
Conditionals
Compact only when a condition is met... | |
only user documents are compacted: | |