Skip to content

Don't run include_in_parent when in copy_to context#87123

Merged
romseygeek merged 6 commits intoelastic:masterfrom
romseygeek:mapper/copy-to-transitivity
Jun 8, 2022
Merged

Don't run include_in_parent when in copy_to context#87123
romseygeek merged 6 commits intoelastic:masterfrom
romseygeek:mapper/copy-to-transitivity

Conversation

@romseygeek
Copy link
Copy Markdown
Contributor

We changed how copy_to is implemented in #79922, which moved
the handling of dots in field names into a specialised parser. Unfortunately,
while doing this we added a bug whereby every time a copy_to directive
is processed for a nested field, the nested field's include_in_parent logic
would be run, meaning that the parent would end up with multiple copies
of the nested child's fields.

This commit fixes this by only running include_in_parent when the parser
is not in a copy_to context. It also fixes another bug that meant the parent
document would contain multiple copies of the ID field.

Fixes #87036

@romseygeek romseygeek added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.4.0 v8.3.1 labels May 25, 2022
@romseygeek romseygeek requested review from javanna and ywelsch May 25, 2022 13:57
@romseygeek romseygeek self-assigned this May 25, 2022
@elasticmachine elasticmachine added the Team:Search Meta label for search team label May 25, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @romseygeek, I've created a changelog YAML for you.

Copy link
Copy Markdown
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this, @romseygeek! I've left one question, looking good o.w.

String nestedPathFieldName = NestedPathFieldMapper.name(indexCreatedVersion);
for (IndexableField field : nestedDoc.getFields()) {
if (field.name().equals(nestedPathFieldName) == false) {
if (field.name().equals(nestedPathFieldName) == false && field.name().equals(IdFieldMapper.NAME) == false) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the logic for adding _id fields to nested docs to the IdFieldMapper.postParse method, similar as we have it for other metadata fields? Then we wouldn't need this exception here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good plan, but I think it might end up being a fairly big change as there are a few places that refer directly to the id field scattered around the place. It also interacts with TSDB in a slightly complicated way - are you OK with doing this as a follow-up?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, follow-up is fine.

@@ -345,6 +345,13 @@ private static void throwEOF(ObjectMapper mapper, String currentFieldName) {
}

private static void nested(DocumentParserContext context, NestedObjectMapper nested) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name does not suggest at all that this method is about adding fields to parent/root doc. Should this be renamed to make the purpose clearer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ have renamed to copyNestedFields

@javanna javanna removed their request for review May 30, 2022 08:59
@romseygeek
Copy link
Copy Markdown
Contributor Author

Thanks for the review @ywelsch, this is ready for another go-around.

Copy link
Copy Markdown
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for digging into this bug, and the fix!

@romseygeek
Copy link
Copy Markdown
Contributor Author

@elasticmachine update branch

@romseygeek romseygeek merged commit 4e1f725 into elastic:master Jun 8, 2022
@romseygeek romseygeek deleted the mapper/copy-to-transitivity branch June 8, 2022 13:02
romseygeek added a commit to romseygeek/elasticsearch that referenced this pull request Jun 8, 2022
We changed how copy_to is implemented in elastic#79922, which moved
the handling of dots in field names into a specialised parser. Unfortunately,
while doing this we added a bug whereby every time a copy_to directive
is processed for a nested field, the nested field's include_in_parent logic
would be run, meaning that the parent would end up with multiple copies
of the nested child's fields.

This commit fixes this by only running include_in_parent when the parser
is not in a copy_to context. It also fixes another bug that meant the parent
document would contain multiple copies of the ID field.

Fixes elastic#87036
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

💚 Backport successful

Status Branch Result
8.3

elasticsearchmachine pushed a commit that referenced this pull request Jun 8, 2022
We changed how copy_to is implemented in #79922, which moved
the handling of dots in field names into a specialised parser. Unfortunately,
while doing this we added a bug whereby every time a copy_to directive
is processed for a nested field, the nested field's include_in_parent logic
would be run, meaning that the parent would end up with multiple copies
of the nested child's fields.

This commit fixes this by only running include_in_parent when the parser
is not in a copy_to context. It also fixes another bug that meant the parent
document would contain multiple copies of the ID field.

Fixes #87036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.3.1 v8.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bad indexing performance in elasticsearch 8.2.0

4 participants