Elasticsearch: Static return values for scripting runtime fields

Created on 15 Jul 2020  路  6Comments  路  Source: elastic/elasticsearch

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

:CorInfrScripting >enhancement CorInfra

Most helpful comment

Phase 1 - improve casting model:

  • ScriptContexts define a set of cast methods that take various types and return the context return value
  • return x is wrapped return cast(x) to ensure the proper return value is always returned

This is along with the current casting model (casting long when double is expected, for example).

All 6 comments

Pinging @elastic/es-core-infra (:Core/Infra/Scripting)

Wrongly closed.

  • We will have contexts that all return primitive arrays
  • We will optimize for single value return by default allocating length one array

    • If script returns non-array, we will automatically fill this array

    • We can also auto-convert List<BoxedTyped> to type[]

  • RT field team will select the appropriate context based on their knowledge of the mappings.

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:

  • ScriptContexts define a set of cast methods that take various types and return the context return value
  • return x is wrapped return cast(x) to ensure the proper return value is always returned

This 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.

Was this page helpful?
0 / 5 - 0 ratings