Emit the script field in ExtendedStatsAggregationBuilder (re-applies #2700) - #4100
Merged
Philippus merged 1 commit intoSep 6, 2026
Merged
Conversation
ExtendedStatsAggregation carries a script and the DSL accepts one, but the builder never serialised it — the only metric aggregation builder with the omission (Avg, Cardinality, Max, Min, Percentiles, Stats, Sum, ValueCount and WeightedAvg all emit it). A scripted extended_stats therefore silently computed over the raw field when a field was also set. Same change as Philippus#2700, which was approved and merged in 2022 — into release/7.10.x, and never forward-ported. The existing SearchDslTest case already sets a script on the aggregation; its golden fixture matched the dropped-script output and is updated accordingly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Owner
|
Nice catch! If you could make the same change towards the 7.x branch |
This was referenced Sep 6, 2026
Merged
Philippus
pushed a commit
that referenced
this pull request
Sep 6, 2026
Backport of #4100 to series/7.x, as requested by the maintainer. ExtendedStatsAggregation carries a script and the DSL accepts one, but the builder never serialised it — the only metric aggregation builder with the omission; the existing SearchDslTest golden fixture pinned the dropped-script output and is updated accordingly. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Philippus
pushed a commit
that referenced
this pull request
Sep 6, 2026
Backport of #4100 to series/8.x, as requested by the maintainer. ExtendedStatsAggregation carries a script and the DSL accepts one, but the builder never serialised it — the only metric aggregation builder with the omission; the existing SearchDslTest golden fixture pinned the dropped-script output and is updated accordingly. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Owner
|
@fupelaqu elastic4s 7.17.26 should be released, please try it out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ExtendedStatsAggregationBuildernever serialisesagg.script, althoughExtendedStatsAggregationcarries the field and the DSL accepts it. This adds the same emission every sibling metric builder already has, mirroringMaxAggregationBuilder's idiom:agg.script.foreach { script => builder.rawField("script", handlers.script.ScriptBuilderFn(script)) }Why it matters
The failure is silent: with both a field and a script set, the emitted JSON contains only
"field", so Elasticsearch computes the extended stats over the raw field and returns a plausible, wrong number — no error anywhere. Checked against the current sources:ExtendedStatsis the only one of the ten metric aggregation builders with this omission (Avg, Cardinality, Max, Min, Percentiles, Stats, Sum, ValueCount and WeightedAvg all emitscript).History — this fix was already approved once
This is a re-application of #2700 (approved and merged on 2022-08-25), which landed on
release/7.10.xand was never forward-ported — so the omission is still present in7.17.25,8.18.xandseries/9.x. The patch here is #2700 adapted to the currenthandlers.script.ScriptBuilderFnlocation and thecustomAggregationssignature.Test
The existing
SearchDslTestcase "should generate correct json for extendedstats aggregation" already setsScript("doc['grade'].value").lang("lua")on the aggregation — its golden fixture matched the dropped-script output, i.e. the test was pinning the bug. The fixture is updated to expect the script node (same fixture change as #2700).green locally on JDK 17 / sbt 2.0.8 — and verified red without the builder change (the fixture update alone fails against the unpatched builder), so the test genuinely asserts the emission.
Backport ask
Would you consider a backport to the 7.17 line (a
7.17.26)? We drive ES 6.x–9.x from one SQL engine (SOFTNETWORK-APP/SoftClient4ES#222) onnl.gn0s1s8.18.x and 7.17.25, and on 7.x our only current option is to reject scriptedextended_statsloudly rather than let it answer wrongly. Happy to open the backport PR against the 7.17 branch if you point me at it.