diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index 36e7a73aa9a..3b21a3bd740 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -473,8 +473,8 @@ public class DateFieldMapper extends FieldMapper { @Override protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { - final DateFieldMapper other = (DateFieldMapper) mergeWith; super.doMerge(mergeWith, updateAllTypes); + final DateFieldMapper other = (DateFieldMapper) mergeWith; if (other.ignoreMalformed.explicit()) { this.ignoreMalformed = other.ignoreMalformed; } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index b728c44cc65..7a4749bcb3c 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -395,4 +395,20 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase { MapperService.MergeReason.MAPPING_UPDATE, randomBoolean())); assertThat(e.getMessage(), containsString("[mapper [release_date] has different [format] values]")); } + + public void testMergeText() throws Exception { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("doc") + .startObject("properties").startObject("date").field("type", "date").endObject() + .endObject().endObject().endObject().string(); + DocumentMapper mapper = indexService.mapperService().parse("doc", new CompressedXContent(mapping), false); + + String mappingUpdate = XContentFactory.jsonBuilder().startObject().startObject("doc") + .startObject("properties").startObject("date").field("type", "text").endObject() + .endObject().endObject().endObject().string(); + DocumentMapper update = indexService.mapperService().parse("doc", new CompressedXContent(mappingUpdate), false); + + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, + () -> mapper.merge(update.mapping(), randomBoolean())); + assertEquals("mapper [date] of different type, current_type [date], merged_type [text]", e.getMessage()); + } }