-
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
Emit multiple fields from the same runtime field script #73252
Conversation
This looks good to me as a practical solution for what needs to get done. Thank you for sharing this draft! A couple thoughts/notes:
|
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.
A couple thoughts
} | ||
|
||
protected final void emit(String field, Object value) { | ||
List<Object> values = this.fieldValues.computeIfAbsent(field, s -> new ArrayList<>()); |
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.
Even without method overloading in painless, we can do some validation here on the type. It could still be fast by using a Set of allowed types. Call value.getClass()
and check for existence in the Set.
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.
Given that in most cases we end up trying to parse what toString
returns when the type is not exactly what we'd like, I am not sure how we would restrict the type of the argument that is provided here. That is maybe a consequence of re-using the existing code for parsing from _source that tries to adapt to the different field types that may be found in _source.
.../src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.object_field.txt
Show resolved
Hide resolved
thanks @jdconrad
I was thinking the same, maybe that is a potential follow-up. I think it deserves more discussion, the two concerns I could see is that we would introduce more leniency in the existing runtime field types, and once we've done that we will hardly have a way to go back. Another concern could be the auto-boxing performance costs, like you said. A big advantage though would be to help users tremendously with their type conversions, which I am sure they struggle with at the moment. |
674eb65
to
aaf6aa4
Compare
e998fed
to
73d4284
Compare
75f3836
to
6440373
Compare
Closing this, we will work in a feature branch for the last couple of things that need to be completed and open another PR when ready. Thanks for the early feedback everybody. |
We have recently introduced support for grok and dissect to the runtime fields Painless context that allows to split a field into multiple fields. Though each runtime field can only emit values for a single field. This PR introduces support for emitting multiple fields from the same script.
Note that this is a draft to share the path forward and gather initial feedback. We have not settled yet on the API. I have introduced support for an object field type on the runtime section, with a new script context that accepts two emit signatures:
We may use the object type, or introduce a new field type.
The way that it emits multiple fields is by returning multiple
MappedFieldType
s fromRuntimeField#asMappedFieldTypes
. The sub-fields are instances of the runtime fields that are already supported, with a little tweak to adapt the script defined by their parent to an artificial script factory for each of the sub-fields that makes the relevant sub-field accessible. This approach allows to reuse all of the existing runtime fields code for the sub-fields.Once we settled on the API, besides addressing the TODOs, we will need to add support for making the new field type indexed by moving its definition to the properties section.
Closes #68203