Scripted metric aggregation
/ Scripted_metric, / Aggregation, / ScriptingScripted metric aggregation #
A metrics aggregation whose result is computed by your own scripts, in four phases, running on Pizza’s sandboxed script engine (see the script language reference).
How it works #
One state map per segment, folded once at the end:
| Phase | Runs | Scope |
|---|---|---|
init_script | once per segment | state, params |
map_script | once per document | state, doc, params |
combine_script | once per segment | state, params |
reduce_script | once, at the end | states, params |
state is a map you own — initialize it in init_script, accumulate into
it in map_script. combine_script folds one segment’s state into a
single value (a script that ends in a statement returns the state itself,
the default when combine_script is omitted). reduce_script receives
all combined values as the states array; if it is omitted, a single
state passes through unchanged and several come back as an array — the
parts, rather than a wrong merge. Builds without the scripting feature
return null for the whole aggregation.