You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data-prepper-plugins/mutate-event-processors/README.md
+51Lines changed: 51 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,55 @@ then when we run with the same input, the processor will parse the message into
54
54
{"message": "value", "newMessage": "new value"}
55
55
```
56
56
57
+
### Iterating over arrays with `iterate_on`
58
+
59
+
The `iterate_on` option allows adding entries to each element of an array. Combined with `disable_root_keys` and `evaluate_when_on_element`, you can reference root-level fields and apply per-element conditions.
- `disable_root_keys: false` allows `value_expression: "/alert_title"` to resolve from the root event
104
+
- `evaluate_when_on_element: true` evaluates `add_to_element_when` against each element, so only elements with `severity == "critical"` receive the new key
105
+
57
106
### Configuration
58
107
* `entries` - (required) - A list of entries to add to an event
59
108
* `key` - (required) - The key of the new entry to be added. One of `key` or `metadata_key` is required.
@@ -62,6 +111,8 @@ then when we run with the same input, the processor will parse the message into
62
111
* `format` - (optional) - A format string to use as value of the new entry to be added. For example, `${key1}-${ke2}` where `key1` and `key2` are existing keys in the event. Required if `value` is not specified.
63
112
* `value_expression` - (optional) - An expression string to use as value of the new entry to be added. For example, `/key` where `key` is an existing key in the event of type Number/String/Boolean. Expressions can also contain functions returning Number/String/Integer. For example `length(/key)` would return the length of the `key` in the event and key must of String type. Please see [expressions syntax document](https://github.com/opensearch-project/data-prepper/blob/2.3/docs/expression_syntax.md) for complete list of supported functions. Required if `value` and `format are not specified.
64
113
* `overwrite_if_key_exists` - (optional) - When set to `true`, if `key` already exists in the event, then the existing value will be overwritten. The default is `false`.
114
+
* `disable_root_keys` - (optional) - When set to `false` and used with `iterate_on`, resolves `value_expression` and `format` against the root event instead of the individual array element. This allows referencing root-level fields during array iteration. Has no effect without `iterate_on`. Default is `true`.
115
+
* `evaluate_when_on_element` - (optional) - When set to `true` and used with `iterate_on` and `add_to_element_when`, evaluates the `add_to_element_when` condition against each individual array element instead of the root event. This enables per-element conditional logic during array iteration. Default is `false`.
Copy file name to clipboardExpand all lines: data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/AddEntryProcessor.java
+32-14Lines changed: 32 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -52,11 +52,15 @@ private static class EntryProperties {
Copy file name to clipboardExpand all lines: data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/AddEntryProcessorConfig.java
+88Lines changed: 88 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -166,6 +166,28 @@ public static class Entry {
166
166
})
167
167
privatebooleanflattenKey = true;
168
168
169
+
@JsonProperty("disable_root_keys")
170
+
@JsonPropertyDescription(
171
+
"When set to <code>false</code> and used with <code>iterate_on</code>, resolves <code>value_expression</code> and <code>format</code> " +
172
+
"against the root event instead of the individual array element. This allows referencing root-level fields during array iteration. " +
173
+
"Has no effect when not used with <code>iterate_on</code>. The default value is <code>true</code>.")
174
+
@AlsoRequired(values = {
175
+
@AlsoRequired.Required(name="iterate_on")
176
+
})
177
+
privatebooleandisableRootKeys = true;
178
+
179
+
@JsonProperty("evaluate_when_on_element")
180
+
@JsonPropertyDescription(
181
+
"When set to <code>true</code> and used with <code>iterate_on</code> and <code>add_to_element_when</code>, " +
182
+
"evaluates the <code>add_to_element_when</code> condition against each individual array element instead of the root event. " +
183
+
"This enables per-element conditional logic during array iteration. " +
0 commit comments