|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index.mapper; |
21 | 21 |
|
22 | | -import java.util.HashSet; |
23 | 22 | import org.apache.lucene.index.IndexableField; |
24 | 23 | import org.elasticsearch.Version; |
25 | 24 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
|
41 | 40 | import java.io.UncheckedIOException; |
42 | 41 | import java.util.Collection; |
43 | 42 | import java.util.Collections; |
| 43 | +import java.util.HashSet; |
44 | 44 | import java.util.function.Function; |
45 | 45 |
|
46 | 46 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
@@ -749,4 +749,31 @@ public void testReorderParentBWC() throws IOException { |
749 | 749 | } |
750 | 750 | } |
751 | 751 | } |
| 752 | + |
| 753 | + public void testMergeNestedMappings() throws IOException { |
| 754 | + MapperService mapperService = createIndex("index1", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, jsonBuilder().startObject() |
| 755 | + .startObject("properties") |
| 756 | + .startObject("nested1") |
| 757 | + .field("type", "nested") |
| 758 | + .endObject() |
| 759 | + .endObject().endObject()).mapperService(); |
| 760 | + |
| 761 | + String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") |
| 762 | + .startObject("nested1").field("type", "nested").field("include_in_parent", true) |
| 763 | + .endObject().endObject().endObject().endObject()); |
| 764 | + |
| 765 | + // cannot update `include_in_parent` dynamically |
| 766 | + MapperException e1 = expectThrows(MapperException.class, () -> mapperService.merge("type", |
| 767 | + new CompressedXContent(mapping1), MergeReason.MAPPING_UPDATE)); |
| 768 | + assertEquals("The [include_in_parent] parameter can't be updated for the nested object mapping [nested1].", e1.getMessage()); |
| 769 | + |
| 770 | + String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") |
| 771 | + .startObject("nested1").field("type", "nested").field("include_in_root", true) |
| 772 | + .endObject().endObject().endObject().endObject()); |
| 773 | + |
| 774 | + // cannot update `include_in_root` dynamically |
| 775 | + MapperException e2 = expectThrows(MapperException.class, () -> mapperService.merge("type", |
| 776 | + new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE)); |
| 777 | + assertEquals("The [include_in_root] parameter can't be updated for the nested object mapping [nested1].", e2.getMessage()); |
| 778 | + } |
752 | 779 | } |
0 commit comments