-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Deprecate "value scripts" on aggregations? #31532
Comments
Pinging @elastic/es-search-aggs |
I'm usually on the side of reducing surface area but I tend to like value scripts due to the fact that they are much simpler and less error-prone if not all documents have a value for the field, or if some have multiple values. However I agree that they lack validation. We should at least make sure that the |
For docs missing a value, I think the Makes sense for multi-values though, no other way for that functionality I guess. We could extend regular scripts to allow returning arrays of values, which would allow the user to deal with multiple values as desired. Then make @rjernst do you know if it's possible to check if a Painless script compiled/used a particular variable? I mean, we could grep for the string but that seems error prone :) If it's possible, I agree that adding validation for |
It is, we do this in order to know whether scripts are using the |
Ah good to know. That seems a viable alternative then. |
IMO having 2 ways of doing the same thing just adds confusion. I am in favor of removing value scripts.
I think this has the same problem that the existing Given that there is no performance difference between the two types of scripts, I favor a single way to do things. |
I believe SQL uses values scripts but I'm not 100% clear on how without looking into it. |
We talked about this in the Search/Aggs meeting and decided that while it would be nice to simplify, it's probably not worth the BWC break and associated hassles. It's a low maintenance item, we can add validation to make sure value scripts are used correctly, and we can avoid a tricky BWC break (moving to a single script would require the user to change the agg syntax and also rewrite the scripts). Lastly, the code needed to deprecate this feature would itself be tricky to maintain since this touches a not-so-great builder. I'm going to open an issue to add validation for |
Today, there is a (little-documented) feature where specifying a
field
+script
on an aggregation will run the script in "value script" mode. Each value in thefield
will be passed to the script under the_value
variable so that the script can modify it, before letting the aggregation collect it.This is a very trappy API, because there are no safeguards from the user specifying a "normal" script that tries to access regular fields. It can lead to confusion like #20773 and #11728
In #20733, we decided to add a
value_script
and deprecatefield
+script
combo. Which is certainly doable, but I'm wondering if we should just deprecate the concept of value scripts entirely? I'm not sure how widespread usage actually is?Besides being confusing, value scripts adds a fair amount of complexity to the code when trying to resolve the ValuesSource, adds another set of Scorer wrappers (
ValuesSource.Numeric.WithScript
,ValuesSource.WithScript
) and adds a bespokesetNextAggregationValue()
in the script implementation solely to satisfy this feature.The text was updated successfully, but these errors were encountered: