Scripted_metric

Scripted metric aggregation

/ Scripted_metric, / Aggregation, / Scripting

Scripted 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:

PhaseRunsScope
init_scriptonce per segmentstate, params
map_scriptonce per documentstate, doc, params
combine_scriptonce per segmentstate, params
reduce_scriptonce, at the endstates, 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.

...