-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Tweak copy_to handling in synthetic _source to account for nested objects #120974
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
54f14ec
Tweak copy_to handling in synthetic _source to account for nested obj…
lkts a43f347
Update docs/changelog/120974.yaml
lkts a8d6463
[CI] Auto commit changes from spotless
d7e25c0
Merge branch 'main' into fix_copy_to_synthetic_source
kkrik-es 085cd52
Address feedback
lkts e8aeccb
Merge branch 'main' into fix_copy_to_synthetic_source
lkts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 120974 | ||
| summary: Tweak `copy_to` handling in synthetic `_source` to account for nested objects | ||
| area: Mapping | ||
| type: bug | ||
| issues: | ||
| - 120831 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,6 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
@@ -161,33 +159,7 @@ public void postParse(DocumentParserContext context) { | |
| return; | ||
| } | ||
|
|
||
| Collection<NameValue> ignoredValuesToWrite = context.getIgnoredFieldValues(); | ||
| if (context.getCopyToFields().isEmpty() == false && indexSettings.getSkipIgnoredSourceWrite() == false) { | ||
| /* | ||
| Mark fields as containing copied data meaning they should not be present | ||
| in synthetic _source (to be consistent with stored _source). | ||
| Ignored source values take precedence over standard synthetic source implementation | ||
| so by adding the `XContentDataHelper.voidValue()` entry we disable the field in synthetic source. | ||
| Otherwise, it would be constructed f.e. from doc_values which leads to duplicate values | ||
| in copied field after reindexing. | ||
| */ | ||
| var mutableList = new ArrayList<>(ignoredValuesToWrite); | ||
| for (String copyToField : context.getCopyToFields()) { | ||
| ObjectMapper parent = context.parent().findParentMapper(copyToField); | ||
| if (parent == null) { | ||
| // There are scenarios when this can happen: | ||
| // 1. all values of the field that is the source of copy_to are null | ||
| // 2. copy_to points at a field inside a disabled object | ||
| // 3. copy_to points at dynamic field which is not yet applied to mapping, we will process it properly on re-parse. | ||
| continue; | ||
| } | ||
| int offset = parent.isRoot() ? 0 : parent.fullPath().length() + 1; | ||
| mutableList.add(new IgnoredSourceFieldMapper.NameValue(copyToField, offset, XContentDataHelper.voidValue(), context.doc())); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is this call to |
||
| } | ||
| ignoredValuesToWrite = mutableList; | ||
| } | ||
|
|
||
| for (NameValue nameValue : ignoredValuesToWrite) { | ||
| for (NameValue nameValue : context.getIgnoredFieldValues()) { | ||
| nameValue.doc().add(new StoredField(NAME, encode(nameValue))); | ||
| } | ||
| } | ||
|
|
||
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.
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.
I think
getCopyToFieldsis not called any more? If so, remove it - and maybe inlinemarkFieldAsCopyTohere and remove it.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.
Not related to this change, but also
cloneWithRecordedSource(...)is not used.Uh oh!
There was an error while loading. Please reload this page.
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.
markFieldAsCopyTois done after parsing and this is done before and i don't know if this is important. I won't experiment.