Runtime fields need to ensure scripts have the return type specified in the mapping. Returning Object would incur dramatic boxing penalties.
We can implement this in the scripting infrastructure by having a context per mapping type, with the different contexts differing only on the execute return value.
Related: https://github.com/elastic/elasticsearch/issues/59332
Pinging @elastic/es-core-infra (:Core/Infra/Scripting)
Wrongly closed.
List<BoxedTyped> to type[]One thought regarding the return type conversions. We've gone to great lengths to make painless agnostic to the signature for particular contexts. Rather than having some kind of magic living within painless to do conversions, what if we were to have conversion methods on the script class itself? This would be similar to the special getters we have which painless looks for, in that the script class (ie script context) completely defines the input and output of the script. So painless would see the return types don't match up, and have some registered conversion methods to look at from when we registered the script context.
Phase 1 - improve casting model:
cast methods that take various types and return the context return valuereturn x is wrapped return cast(x) to ensure the proper return value is always returnedThis is along with the current casting model (casting long when double is expected, for example).
Closing this as all requirements are implemented, created #61389 to make them easier on implementers.
Most helpful comment
Phase 1 - improve casting model:
castmethods that take various types and return the context return valuereturn xis wrappedreturn cast(x)to ensure the proper return value is always returnedThis is along with the current casting model (casting
longwhendoubleis expected, for example).