-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
SCRIPTING: Move Aggregation Script Context to its own class #33820
SCRIPTING: Move Aggregation Script Context to its own class #33820
Conversation
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a WIP, but I left a few comments for general direction I think we should take this.
} | ||
|
||
/** Return the score of the current document. */ | ||
public double getScore() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have score accessible as score
and _score
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was going to ask you, but yea I think score
can go away here right?
* <p> | ||
* @param value per-document value, typically a String, Long, or Double | ||
*/ | ||
public void setNextAggregationValue(Object value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At minimum this should be typed (we should have separate script classes for each underlying doc values type), but I would much rather this be built into the script itself, so instead of setting the value, an iterate type call is made, similar to the doc values api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjernst as it turns out this isn't so trivial :(
Determining the exact type of the script upstream would require a lot of refactoring starting with org.elasticsearch.search.aggregations.support.ValuesSourceConfig
(did some initial cleanups towards that in #34323).
Maybe we should do that in a next step?
/** | ||
* Return the result as a long. This is used by aggregation scripts over long fields. | ||
*/ | ||
public long runAsLong() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need these methods if we make typed versions of scripts, where execute would then return the correct type. Additionally, don't we always return double for all numeric fields (ie runAsLong isn't actually used)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in: org.elasticsearch.search.aggregations.support.ValuesSource.Numeric.WithScript.LongValues
.
but you're right typed versions of this context should be possible, will try tomorrow :)
|
||
public AggregationScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { | ||
this.params = new ParameterMap(new HashMap<>(params), DEPRECATIONS); | ||
this.leafLookup = lookup.getLeafSearchLookup(leafContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think doc
or _score
works in value aggregation scripts? Looking at the user of this, I don't see where setDocument is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about the score (though a scorer is set for this script in e.g org.elasticsearch.search.aggregations.support.values.ScriptBytesValues#setScorer
) but the document is set in many places like org.elasticsearch.search.aggregations.support.values.ScriptLongValues#advanceExact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I see the calls to setDocument now. It still looks like the scorer is not set anywhere, but it also looks quite deceptive so I fear there is something more complex going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this at least helps us get rid of SearchScript uses, so let's get this in with the generic Object return values and such, and then work on refactoring to have both typed and value/non-value specific versions (I still think _value scripts should not provide _score or doc). LGTM.
@rjernst thanks, I'll still have to fix the expression case here but that should be pretty quick+easy. Will try to hurry that up :) |
@rjernst alright enabled expressions here too the same way I did it for the terms set script. See if you're still ok with it ? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
this.params.putAll(leafLookup.asMap()); | ||
} | ||
|
||
protected AggregationScript() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this empty ctor needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjernst like in the terms set case (same code there) this is used by expressions because they don't use the leaf lookup (just to avoid the null checks and logic in the constructor).
* master: Do not update number of replicas on no indices (elastic#34481) Core: Remove two methods from AbstractComponent (elastic#34336) Use RoleRetrievalResult for better caching (elastic#34197) Revert "Search: Fix spelling mistake in Javadoc (elastic#34480)" Search: Fix spelling mistake in Javadoc (elastic#34480) Docs: improve formatting of Query String Query doc page (elastic#34432) Tests: Handle epoch date formatters edge cases (elastic#34437) Test: Fix running with external cluster Fix handling of empty keyword in terms aggregation (elastic#34457) [DOCS] Fix tag in SecurityDocumentationIT [Monitoring] Add additional necessary mappings for apm-server (elastic#34392) SCRIPTING: Move Aggregation Script Context to its own class (elastic#33820) MINOR: Remove Deadcode in ExpressionTermSetQuery (elastic#34442) HLRC: Get SSL Certificates API (elastic#34135)
* SCRIPTING: Move Aggregation Script Context to its own class
WIP