diff --git a/docs/changelog/108867.yaml b/docs/changelog/108867.yaml new file mode 100644 index 0000000000000..545349dd84aeb --- /dev/null +++ b/docs/changelog/108867.yaml @@ -0,0 +1,6 @@ +pr: 108867 +summary: Fix for raw mapping merge of fields named "properties" +area: Mapping +type: bug +issues: + - 108866 diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java index 2227c54871352..28df2fad32cbb 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java @@ -415,7 +415,7 @@ public static void mergeDefaults(Map content, Map {})); + mapperService.merge("_doc", List.of(mapping1, mapping2), MergeReason.INDEX_TEMPLATE); + assertEquals(""" + { + "_doc" : { + "properties" : { + "properties" : { + "properties" : { + "child1" : { + "type" : "text", + "fields" : { + "keyword" : { + "type" : "keyword" + } + } + }, + "child2" : { + "type" : "integer" + }, + "child3" : { + "properties" : { + "grandchild" : { + "type" : "long" + } + } + } + } + } + } + } + }""", Strings.toString(mapperService.documentMapper().mapping(), true, true)); + + Mapper propertiesMapper = mapperService.documentMapper().mapping().getRoot().getMapper("properties"); + assertThat(propertiesMapper, instanceOf(ObjectMapper.class)); + Mapper childMapper = ((ObjectMapper) propertiesMapper).getMapper("child1"); + assertThat(childMapper, instanceOf(FieldMapper.class)); + assertEquals("text", childMapper.typeName()); + assertEquals(2, childMapper.getTotalFieldsCount()); + childMapper = ((ObjectMapper) propertiesMapper).getMapper("child2"); + assertThat(childMapper, instanceOf(FieldMapper.class)); + assertEquals("integer", childMapper.typeName()); + assertEquals(1, childMapper.getTotalFieldsCount()); + childMapper = ((ObjectMapper) propertiesMapper).getMapper("child3"); + assertThat(childMapper, instanceOf(ObjectMapper.class)); + Mapper grandchildMapper = ((ObjectMapper) childMapper).getMapper("grandchild"); + assertEquals("long", grandchildMapper.typeName()); + } + public void testMergeUntilLimit() throws IOException { CompressedXContent mapping1 = new CompressedXContent(""" {