flow
Search…
append
Using the append reduction strategy
append works with arrays, and extends the left-hand array with items from the right-hand side.
1
collections:
2
- name: example/reductions/append
3
schema:
4
type: object
5
reduce: { strategy: merge }
6
properties:
7
key: { type: string }
8
value:
9
# Append only works with type "array".
10
# Others will throw an error at build time.
11
type: array
12
reduce: { strategy: append }
13
required: [key]
14
key: [/key]
15
16
tests:
17
"Expect we can append arrays":
18
- ingest:
19
collection: example/reductions/append
20
documents:
21
- { key: "key", value: [1, 2] }
22
- { key: "key", value: [3, null, "abc"] }
23
- verify:
24
collection: example/reductions/append
25
documents:
26
- { key: "key", value: [1, 2, 3, null, "abc"] }
Copied!
The right-hand side must always be an array. The left-hand side may be null, in which case the reduction is treated as a no-op and its result remains null. This can be combined with schema conditionals to toggle whether reduction-reduction should be done or not.
Last modified 3mo ago
Copy link