-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Kibana scripted fields to runtime fields #69631
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
Comments
Pinging @elastic/es-core-infra (Team:Core/Infra) |
|
At least initially I'm not feeling very confident about the first option but perhaps I can get there. Obviously but If nothing else I'd need a complete set of examples to work from as a set of test cases. Perhaps @stu-elastic or someone else knows how to simplify the problem. |
Ahh curlies are not relevant, that was mistyped. The rest is standard expression parsing to do it perfectly. I suspect there'll be a ton of mileage gained from simply grabbing until the next |
Assuming there's no implicit return, here's an idea of the flavors of return statements one could encounter: |
@stu-elastic Thanks, thats looking a lot more approachable. Might it be possible for |
Yes. |
Here's another idea, why not do the same thing kibana does when it takes kibana scripted fields and uses them as filters in discover? In that case, kibana generates some methods and embeds the old script in a lambda:
Instead of doing the string transform with
This reuses the script transform infrastructure already in kibana while avoiding any parsing. The same limitations in these transforms as already apply to kibana scripted fields used as filters in discover. If there's a syntax error, it'd show up in a call to the runtime fields execute api #70467 |
If I remember correctly, this doesn't work if there are function definitions as part of the script, correct? What other code structures can't be dropped inside a function? |
|
One other caveat, that is a long term fix @stu-elastic is working on actually is our "static" methods that require the Script pointer will not work once we put them inside a user-defined function, but most of these aren't used often. Example:
|
Ahh good catch @jdconrad. The nice thing is both of those limitations would fail at compile time, so they would be detectable via the execute api. |
Can you say more about this or point me to the docs? Looking at the example code I just see a function invocation with two arguments.
Compilation failures strike me as an ideal way to catch failed scripts. |
@mattkime I'll go through our allow lists and see if I can gather up the specific methods. Our documentation is likely out-of-date for all them, and probably a bit unwieldy to gather them through there. |
One thing worth pointing out is that wrapping scripts doesn't provide a very good introduction to writing a runtime script. I'm not sure if that will affect which route we choose but its worth mentioning. |
@mattkime @jimczi @rdnm @stu-elastic @rjernst I wanted to get a better understanding of what can be provided client side for this migration, so I took a pass at this problem with the constraints of doing a string to string translation using standard data structures. The idea is the Java code I have is a good approximation of the equivalent TypeScript code. Doing better on the server-side may be possible, but would require a decent amount of investigation. I have stored the code in a test case class on this branch in this file (https://github.com/jdconrad/elasticsearch/blob/kmig/modules/lang-painless/src/test/java/org/elasticsearch/painless/AdditionTests.java#L24). The implementation is in replaceReturnWithEmit. Notes:
Caveats:
Some examples:
The above ignores strings as part of the field names. It then takes an implicit return value and adds an emit to the last statement. Another more complex example:
The above ignores the returns as part of user-defined functions and lambdas. It ignores comments. It converts main body statements with return to emit(...); return; with appropriate braces around single statement else. It converts the last statement to emit a value for an implicit return. |
My initial reaction looking at that code - its what I thought this would require but I lack the experience to do it confidently. The code looks easy to translate into typescript although I'd want a pretty extensive test suite to go with it.
Kibana scripted fields does support this. That said, we'd probably be okay not supporting it. |
Moved this code to (https://github.com/jdconrad/elasticsearch/blob/kmig/modules/lang-painless/src/test/java/org/elasticsearch/painless/MigrationTests.java) for now. Added 72 tests. TODOs embedded to add more. Pausing for now. |
@jdconrad Our current plan is to not provide an automated method of converting scripted fields. Still good to have this in case something changes. |
Let's close for now, if the plans change please reopen. |
Uh oh!
There was an error while loading. Please reload this page.
The goal is to translate a kibana scripted field to a runtime field.
Differences
emit vs return
return
values, runtime fieldsemit
values.emit
appends a value to an internally managed list and does not halt executionreturn
ing a value in a scripted field halts execution. There is no implicit list management.Types
number
,string
,date
orboolean
. The coereced type is selected by the user. The return type for the painless context isObject
.List
ofObject
s).boolean
,date
(from along
),double
,long
,String
,GeoPoint
,IP
(from aString
).Contexts
emit
ed type, egip_script_field
.Required Return Value
return
a value, which may benull
.emit
a value.Implicit returns
return
.emit
from runtime fields.Options
return x;
->
emit(x); return;
cc: @mattkime @jdconrad
The text was updated successfully, but these errors were encountered: