Skip to content

Migrate scripted metric agg scripts to new ScriptContext design and use context variables for agg state #29328

@rationull

Description

@rationull

Per discussion on #28819 it would be nice to have custom ScriptContexts (and the abstract Script classes to go with them) for the scripts involved in scripted metric aggregations. One goal is to provide the _agg/_aggs variable as a script context variable rather than in the params map. Another goal is to continue migrating scripts to use the new dedicated context design.

Per discussion in #30111 _agg and _aggs shall become state and states when moved into the context.

The four script types in play, with their desired context properties:

  • init: params map, agg map
  • map: params map, agg map, doc, score (anything else? Do we need to do anything for _fields and _source here? I have a feeling we don't but I'm not sure)
  • combine: params map, agg map
  • reduce: params map, aggs array

We'll also need to modify ScriptedMetricAggregator where it pulls out the _agg param to use the new context variable instead.

Another concern is backwards compatibility since ultimately we would remove _agg/_aggs from params. I would guess the strategy here is to leave both the old and the new in place for at least one major release. Would we emit a deprecation warning whenever scripted metric aggregations are used or somehow try to detect uses of the old _agg/_aggs params in scripts and only emit a warning then? Any cases where we touch the agg variable content in code would need to honor the legacy _agg/_aggs content if present as well. I would assume we can rule that either the new context variable or the legacy params (not a mix of both) would be used within a given set of aggregation scripts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions