Skip to content

Commit adb02b7

Browse files
gwbrownkcm
authored andcommitted
Label required scripts in Scripted Metric Agg docs (#35051)
When combine_script and reduce_script were made into required parameters for Scripted Metric aggregations in #33452, the docs were not updated to reflect that. This marks those parameters as required in the documentation.
1 parent 8dcf823 commit adb02b7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ POST ledger/_search?size=0
1515
"aggs": {
1616
"profit": {
1717
"scripted_metric": {
18-
"init_script" : "state.transactions = []",
19-
"map_script" : "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)", <1>
18+
"init_script" : "state.transactions = []", <1>
19+
"map_script" : "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)",
2020
"combine_script" : "double profit = 0; for (t in state.transactions) { profit += t } return profit",
2121
"reduce_script" : "double profit = 0; for (a in states) { profit += a } return profit"
2222
}
@@ -27,7 +27,7 @@ POST ledger/_search?size=0
2727
// CONSOLE
2828
// TEST[setup:ledger]
2929

30-
<1> `map_script` is the only required parameter
30+
<1> `init_script` is an optional parameter, all other scripts are required.
3131

3232
The above aggregation demonstrates how one would use the script aggregation compute the total profit from sale and cost transactions.
3333

@@ -121,22 +121,22 @@ init_script:: Executed prior to any collection of documents. Allows the ag
121121
+
122122
In the above example, the `init_script` creates an array `transactions` in the `state` object.
123123

124-
map_script:: Executed once per document collected. This is the only required script. If no combine_script is specified, the resulting state
124+
map_script:: Executed once per document collected. This is a required script. If no combine_script is specified, the resulting state
125125
needs to be stored in the `state` object.
126126
+
127127
In the above example, the `map_script` checks the value of the type field. If the value is 'sale' the value of the amount field
128128
is added to the transactions array. If the value of the type field is not 'sale' the negated value of the amount field is added
129129
to transactions.
130130

131-
combine_script:: Executed once on each shard after document collection is complete. Allows the aggregation to consolidate the state returned from
132-
each shard. If a combine_script is not provided the combine phase will return the aggregation variable.
131+
combine_script:: Executed once on each shard after document collection is complete. This is a required script. Allows the aggregation to
132+
consolidate the state returned from each shard.
133133
+
134134
In the above example, the `combine_script` iterates through all the stored transactions, summing the values in the `profit` variable
135135
and finally returns `profit`.
136136

137-
reduce_script:: Executed once on the coordinating node after all shards have returned their results. The script is provided with access to a
138-
variable `states` which is an array of the result of the combine_script on each shard. If a reduce_script is not provided
139-
the reduce phase will return the `states` variable.
137+
reduce_script:: Executed once on the coordinating node after all shards have returned their results. This is a required script. The
138+
script is provided with access to a variable `states` which is an array of the result of the combine_script on each
139+
shard.
140140
+
141141
In the above example, the `reduce_script` iterates through the `profit` returned by each shard summing the values before returning the
142142
final combined profit which will be returned in the response of the aggregation.

0 commit comments

Comments
 (0)