From 8f8ae8f57794ba5b9e5f540938f19a93827d06dd Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 18 Aug 2016 09:17:24 +0200 Subject: [PATCH] Mapping updates on objects should propagate `include_an_all`. #20051 Today you can't update `include_an_all` on an existing object. The bug affects 2.x too. --- .../index/mapper/ObjectMapper.java | 1 + .../index/mapper/ObjectMapperTests.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java index f3941f9b25f..201f5b63911 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java @@ -430,6 +430,7 @@ public class ObjectMapper extends Mapper implements Cloneable { } } + this.includeInAll = mergeWith.includeInAll; if (mergeWith.dynamic != null) { this.dynamic = mergeWith.dynamic; } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java index b5a31e49a60..276717303da 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java @@ -24,8 +24,12 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperParsingException; +import org.elasticsearch.index.mapper.MapperService.MergeReason; +import org.elasticsearch.index.mapper.ObjectMapper.Dynamic; import org.elasticsearch.test.ESSingleNodeTestCase; +import java.io.IOException; + import static org.hamcrest.Matchers.containsString; public class ObjectMapperTests extends ESSingleNodeTestCase { @@ -155,4 +159,27 @@ public class ObjectMapperTests extends ESSingleNodeTestCase { .string(); createIndex("test").mapperService().documentMapperParser().parse("tweet", new CompressedXContent(mapping)); } + + public void testMerge() throws IOException { + String mapping = XContentFactory.jsonBuilder().startObject() + .startObject("type") + .startObject("properties") + .startObject("foo") + .field("type", "keyword") + .endObject() + .endObject() + .endObject().endObject().string(); + MapperService mapperService = createIndex("test").mapperService(); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, false); + assertNull(mapper.root().includeInAll()); + assertNull(mapper.root().dynamic()); + String update = XContentFactory.jsonBuilder().startObject() + .startObject("type") + .field("include_in_all", false) + .field("dynamic", "strict") + .endObject().endObject().string(); + mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.MAPPING_UPDATE, false); + assertFalse(mapper.root().includeInAll()); + assertEquals(Dynamic.STRICT, mapper.root().dynamic()); + } }