Skip to content

Assign the right path to objects merged when parsing mappings#89389

Merged
javanna merged 5 commits intoelastic:mainfrom
javanna:fix/build_mappers_builder_context
Aug 17, 2022
Merged

Assign the right path to objects merged when parsing mappings#89389
javanna merged 5 commits intoelastic:mainfrom
javanna:fix/build_mappers_builder_context

Conversation

@javanna
Copy link
Copy Markdown
Contributor

@javanna javanna commented Aug 16, 2022

When parsing mappings, we may find a field with same name specified twice, either
because JSON duplicate keys are allowed, or because a mix of object notation and dot
notation is used when providing mappings. The same can happen when applying dynamic
mappings as part of parsing an incoming document, as well as when merging separate
index templates that may contain the definition for the same field using a
mix of object notation and dot notation.

While we propagate the MapperBuilderContext across merge calls thanks to #86946, we do not
propagate the right context when we call merge on objects as part of parsing/building
mappings. This causes a situation in which the leaf fields that result from the merge
have the wrong path, which misses the first portion e.g. sub.field instead of obj.sub.field.

This commit applies the correct mapper builder context when building the object mapper builder
and two objects with same name are found.

The scenario in which this bug was triggered is limited: the same document or mappings need to have the same field specified twice, using the object notation as well as the dot notation. In this case, we would end up indexing the leaf fields that were merged (the leaves that both object held) in the wrong lucene fields, which can only be fixed through a reindex. Closing and reopening the index triggers a reparsing of the mappings that addressed the problem though.

Relates to #86946

Closes #88573

When parsing mappings, we may find a field with same name specified twice, either
because JSON duplicate keys are allowed, or because a mix of object notation and dot
notation is used when providing mappings. The same can happen when applying dynamic
mappings as part of parsing an incoming document, as well as when merging separate
index templates that may contain the definition for the same field using a
mix of object notation and dot notation.

While we propagate the MapperBuilderContext across merge calls thanks to elastic#86946, we do not
propagate the right context when we call merge on objects as part of parsing/building
mappings. This causes a situation in which the leaf fields that result from the merge
have the wrong path, which misses the first portion e.g. sub.field instead of obj.sub.field.

This commit applies the correct mapper builder context when building the object mapper builder
and two objects with same name are found.

Relates to elastic#86946

Closes elastic#88573
@javanna javanna added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.4.1 v8.5.0 labels Aug 16, 2022
@javanna javanna requested a review from romseygeek August 16, 2022 14:54
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Aug 16, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@javanna javanna added the auto-backport Automatically create backport pull requests when merged label Aug 17, 2022
Copy link
Copy Markdown
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

LGTM

@javanna javanna merged commit c038a91 into elastic:main Aug 17, 2022
javanna added a commit to javanna/elasticsearch that referenced this pull request Aug 17, 2022
…c#89389)

When parsing mappings, we may find a field with same name specified twice, either
because JSON duplicate keys are allowed, or because a mix of object notation and dot
notation is used when providing mappings. The same can happen when applying dynamic
mappings as part of parsing an incoming document, as well as when merging separate
index templates that may contain the definition for the same field using a
mix of object notation and dot notation.

While we propagate the MapperBuilderContext across merge calls thanks to elastic#86946, we do not
propagate the right context when we call merge on objects as part of parsing/building
mappings. This causes a situation in which the leaf fields that result from the merge
have the wrong path, which misses the first portion e.g. sub.field instead of obj.sub.field.

This commit applies the correct mapper builder context when building the object mapper builder
and two objects with same name are found.

Relates to elastic#86946

Closes elastic#88573
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

💚 Backport successful

Status Branch Result
8.4

grcevski pushed a commit to grcevski/elasticsearch that referenced this pull request Aug 17, 2022
…c#89389)

When parsing mappings, we may find a field with same name specified twice, either
because JSON duplicate keys are allowed, or because a mix of object notation and dot
notation is used when providing mappings. The same can happen when applying dynamic
mappings as part of parsing an incoming document, as well as when merging separate
index templates that may contain the definition for the same field using a
mix of object notation and dot notation.

While we propagate the MapperBuilderContext across merge calls thanks to elastic#86946, we do not
propagate the right context when we call merge on objects as part of parsing/building
mappings. This causes a situation in which the leaf fields that result from the merge
have the wrong path, which misses the first portion e.g. sub.field instead of obj.sub.field.

This commit applies the correct mapper builder context when building the object mapper builder
and two objects with same name are found.

Relates to elastic#86946

Closes elastic#88573
@mark-vieira mark-vieira added v8.4.0 and removed v8.4.1 labels Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.4.0 v8.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mapper_parsing_exception (Field is defined more than once) in 8.3.2

4 participants