Skip to content

Detect when copying to a non existent field #127098

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BinhMike
Copy link

This commit addresses the problem where copy_to references could silently point to non-existent fields when dynamic: false is set in the index mappings.

Previously, if a user added a copy_to reference to a field that had not been explicitly defined and dynamic mappings were disabled, the request would succeed without warning—even though nothing would be copied at runtime. This behavior was misleading and could result in lost data or unexpected query results.

With this change, we now explicitly validate copy_to targets during mapping validation:

If dynamic mappings are disabled,

and a copy_to field is not declared in the mappings,

we throw an IllegalArgumentException during DocumentMapper.validate() with a clear message.

This ensures users are aware of invalid copy_to targets up front and prevents silent mapping misconfigurations.

Fixes: #112812
🧪 Validation is integrated into the existing DocumentMapper#validate() lifecycle
📄 Affected area: Mapping validation logic during index creation or updates

…rs by data type) that is referenced consistently in both resolveType and toEvaluator
…ntly point to non-existent fields when dynamic: false is set in the index mappings
Copy link

❌ Author of the following commits did not sign a Contributor Agreement:
765e633, a5c791f

Please, read and sign the above mentioned agreement if you want to contribute to this project

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team v9.1.0 labels Apr 20, 2025
@gbanasiak gbanasiak added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Apr 28, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Apr 28, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-contributor Pull request authored by a developer outside the Elasticsearch team :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect when copying to a non-existent field when dynamic mappings are disabled
3 participants