[Automatic Import] Safely access non-identifier fields in Painless if context#205220
Merged
ilyannn merged 9 commits intoelastic:mainfrom Jan 3, 2025
Merged
[Automatic Import] Safely access non-identifier fields in Painless if context#205220ilyannn merged 9 commits intoelastic:mainfrom
ilyannn merged 9 commits intoelastic:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release Note
Fixes how Automatic Import generates accesses for the field names that are not valid Painless identifiers.
Summary
Closes #205024
We add utility functions to access nested fields in Painless in a safe way and modify the existing ECS generation logic to use them.
This access happens using the
object?.get("field")syntax for complex cases, while falling back to the familiarctx.fieldfor the cases wherefieldis a valid Painless identifier andctxis known to be non-nullable.In the future this should be taken care of by the new
$('a.b.c', defaultValue)accessor function (elastic/elasticsearch#101274). For now, it's not available:This takes care of the compile-time correctness of field accesses. Note that it is still possible for generated pipelines to fail in runtime on unexpected input, e.g. accessing a nested field
a.bfails for the document of the form{"a": "string"}.Testing
The two utility files we add are fully covered with unit tests:
.
Here's the generated package for logs containing only the
@timestampfield:Checklist
release_note:*label is applied per the guidelines