|
|
@@ -742,4 +742,31 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase {
|
|
|
assertThat(doc.docs().get(1).get("nested1.field2"), equalTo("4"));
|
|
|
assertThat(doc.docs().get(2).get("field"), equalTo("value"));
|
|
|
}
|
|
|
+
|
|
|
+ public void testMergeNestedMappings() throws IOException {
|
|
|
+ MapperService mapperService = createIndex("index1", Settings.EMPTY, jsonBuilder().startObject()
|
|
|
+ .startObject("properties")
|
|
|
+ .startObject("nested1")
|
|
|
+ .field("type", "nested")
|
|
|
+ .endObject()
|
|
|
+ .endObject().endObject()).mapperService();
|
|
|
+
|
|
|
+ String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
|
|
+ .startObject("nested1").field("type", "nested").field("include_in_parent", true)
|
|
|
+ .endObject().endObject().endObject().endObject());
|
|
|
+
|
|
|
+ // cannot update `include_in_parent` dynamically
|
|
|
+ MapperException e1 = expectThrows(MapperException.class, () -> mapperService.merge("type",
|
|
|
+ new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE));
|
|
|
+ assertEquals("The [include_in_parent] parameter can't be updated for the nested object mapping [nested1].", e1.getMessage());
|
|
|
+
|
|
|
+ String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
|
|
+ .startObject("nested1").field("type", "nested").field("include_in_root", true)
|
|
|
+ .endObject().endObject().endObject().endObject());
|
|
|
+
|
|
|
+ // cannot update `include_in_root` dynamically
|
|
|
+ MapperException e2 = expectThrows(MapperException.class, () -> mapperService.merge("type",
|
|
|
+ new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE));
|
|
|
+ assertEquals("The [include_in_root] parameter can't be updated for the nested object mapping [nested1].", e2.getMessage());
|
|
|
+ }
|
|
|
}
|