Merging mappings with subobjects: false
can result in invalid mappings
#103497
Labels
>bug
:Search Foundations/Mapping
Index mappings, including merging and defining field types
Team:Search Foundations
Meta label for the Search Foundations team in Elasticsearch
Elasticsearch Version
8.11
Installed Plugins
No response
Java Version
bundled
OS Version
macOS 14.2
Problem Description
I found a way to corrupt the mappings using
subobjects: false
. The reason is that ES is only validating that there must be no object mappers within in an object that's configured withsubobjects: false
while parsing mappings:elasticsearch/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java
Lines 312 to 320 in fb5c744
However, it's possible to create an invalid mapping using two distinct mapping updates that are valid on their own but invalid when the mappings are merged.
This invalid mapping merge is caught in testing with this assertion that re-parses the merged mappings:
elasticsearch/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Line 526 in fb5c744
Since assertions are disabled in production, it's possible to create an invalid mapping.
To fix this, we could enable the assertion in production, too. Or, maybe a better way would be to catch the error scenario earlier, during mapping merge.
In these cases, we could check if we're trying to add an
ObjectMapper
even though subobjects are disabled:elasticsearch/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java
Lines 546 to 549 in fb5c744
Steps to Reproduce
Logs (if relevant)
No response
The text was updated successfully, but these errors were encountered: