Scripts landed across the whole request path — the engine runs the
examples from the Elasticsearch docs unmodified. The engine is Rhai
rather than Painless, but doc['x'].value, _score and
params.<name> mean what they mean there.
Aggregations.scripted_metric
runs your own four-phase map/reduce — init_script, map_script,
combine_script, reduce_script — with per-segment states folded at the
end. The single-value metric aggs (sum, avg, min, max,
cardinality) accept a script in place of a field
(
details),
and pipeline aggregations keep their buckets_path arithmetic.
Compute extra values for each hit, at fetch time, from the hit’s own
_source — like
highlighting, but producing numbers and
strings instead of fragments. Scripts run on Pizza’s sandboxed script
engine (see
the script language reference),
only for the hits actually returned on the page.
Every returned hit carries the computed values under fields, as arrays:
Scripts in the search request: script_score to compute
the score, a script predicate in a boolean filter, and a _script sort
key. All run on Pizza’s sandboxed script engine (see
the script language reference) —
Rhai, not Painless, but the doc['x'].value, _score,
params.<name> spellings run unmodified.
Wrap a query; the script’s value replaces the score. The script sees
_score (the wrapped query’s BM25 score), doc (the hit’s _source in
doc-values shape) and params:
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).
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.