New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate scripted metric agg scripts to new ScriptContext design and use context variables for agg state #29328
Comments
@colings86 after discussing a bit with @rjernst I'm interested in taking a shot at this if that's alright with you. It'll probably take me a bit of time as my availability/hobby time is a little spotty (plus it'll be some time figuring out the codebase) but it seems like a pretty low priority issue so guessing that won't be a problem unless this is something you'd prefer to handle more internally. Seems prudent to split the design change and the params._agg -> agg change into separate PRs and they could even be separate tasks too if you think that's more appropriate. |
@rjernst one thing I'm not sure of is whether the map script will be a bigger deal than the rest since it's a SearchScript, not just an ExecutableScript. Should the SearchScript class+context really be replaced in this case or do we need to e.g. derive from SearchScript to retain all its behavior in addition to the new context variables? Not sure if there are any deeper SearchScript related special cases in the system in general or in Painless that would need to be modified in that case. |
No need for the map script to derive from search or executable script. The only reason it is a search script right now is to give access to doc values, but that can be done with the new script context, and without trappily exposing (as search script does) _score. |
_score is currently documented as being available for aggregation scripts but sounds like that's not something that needs to carry forward with this change then. |
I did not realize that. I'll let @colings86 comment on why that is necessary. If it is, then a subclass of a SearchScript makes sense. |
Pinging @elastic/es-search-aggs |
_score is made available to most (if not all) aggregation scripts. Personally I do not know the use cases for wanting to aggregate on the score but I know that users do this so at least for now I think we would need to maintain this functionality unless its a big problem for this change? I think we could also open a discussion about whether we should continue to expose the score to aggregation scripts. For the scripted_metric aggregation only the map script needs to be a SearchScript as the other scripts are not involved in the query phase. |
After further thought, I don't think subclassing SearchScript (or a future ScoringScript based on script contexts I plan to add) will work, as the |
@colings86 @rjernst any feedback on this? Other than changes to context parameter naming and writing a more detailed commit comment, I think any further changes as mentioned in the PR #30111 could be done in separate PRs to keep things simple. Plus any changes that come from your feedback, of course. If you’d rather I make progress on some of the outstanding items before merging this (to avoid leaving work in progress from an outside contributor) then let me know. Another thing is if you’d rather keep the script context refactor separate from adding the new way to access the agg map, then I would be happy to pull the new context variables out into a separate PR. |
@rationull I left comments on the PR and set it for CI testing |
…30111) * Migrate scripted metric aggregation scripts to ScriptContext design #29328 * Rename new script context container class and add clarifying comments to remaining references to params._agg(s) * Misc cleanup: make mock metric agg script inner classes static * Move _score to an accessor rather than an arg for scripted metric agg scripts This causes the score to be evaluated only when it's used. * Documentation changes for params._agg -> agg * Migration doc addition for scripted metric aggs _agg object change * Rename "agg" Scripted Metric Aggregation script context variable to "state" * Rename a private base class from ...Agg to ...State that I missed in my last commit * Clean up imports after merge
With #30111 merged, the bulk of this is done. There will be two more (much smaller) PRs, one for a deprecation warning and system property control of access to the deprecated @colings86 @rjernst I have these changes implemented already -- I will give them another look and create the next PR when I get a chance either today or tomorrow. |
@colings86 I just created PR #31597 adding a deprecation warning and a path forward for disabling the legacy |
…30111) * Migrate scripted metric aggregation scripts to ScriptContext design #29328 * Rename new script context container class and add clarifying comments to remaining references to params._agg(s) * Misc cleanup: make mock metric agg script inner classes static * Move _score to an accessor rather than an arg for scripted metric agg scripts This causes the score to be evaluated only when it's used. * Documentation changes for params._agg -> agg * Migration doc addition for scripted metric aggs _agg object change * Rename "agg" Scripted Metric Aggregation script context variable to "state" * Rename a private base class from ...Agg to ...State that I missed in my last commit * Clean up imports after merge
Sanity check @rjernst @nik9000 there are some leftover script files in |
Yes those can be removed. They are from when we had file scripts. |
With the deprecation/bwc removal commit on master I think there's no more work to be done under this task. @rjernst @colings86 do you agree? |
@rationull yep you are right, this can be closed now. Thanks again for your work on this |
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 becomestate
andstates
when moved into the context.The four script types in play, with their desired context properties:
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.
The text was updated successfully, but these errors were encountered: