This is a cache of https://www.elastic.co/guide/en/elasticsearch/painless/8.19/painless-metric-agg-init-context.html. It is a snapshot of the page as it appeared on 2025-11-22T03:25:39.872+0000.
Metric aggregation initialization context | Painless Scripting Language [8.19] | Elastic

Metric aggregation initialization context

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Metric aggregation initialization context

edit

Use a Painless script to initialize values for use in a scripted metric aggregation. An initialization script is run prior to document collection once per shard and is optional as part of the full metric aggregation.

Variables

params (Map, read-only)
User-defined parameters passed in as part of the query.
state (Map)
Empty Map used to add values for use in a map script.

Side Effects

state (Map)
Add values to this Map to for use in a map. Additional values must be of the type Map, List, String or primitive.

Return

void
No expected return value.

API

The standard Painless API is available.