Detect when copying to a non existent field #127098
Open
+336
−14
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.
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