diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java index c1e65fd391d..65b78ceb5e8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper.object; import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.Sets; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.xcontent.ToXContent; @@ -35,6 +36,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Set; import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.common.xcontent.support.XContentMapValues.*; @@ -58,6 +60,8 @@ public class RootObjectMapper extends ObjectMapper { protected final List dynamicTemplates = newArrayList(); + // we use this to filter out seen date formats, because we might get duplicates during merging + protected Set seenDateFormats = Sets.newHashSet(); protected List dateTimeFormatters = newArrayList(); protected boolean dateDetection = Defaults.DATE_DETECTION; @@ -74,21 +78,14 @@ public class RootObjectMapper extends ObjectMapper { public Builder dateTimeFormatter(Iterable dateTimeFormatters) { for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) { - this.dateTimeFormatters.add(dateTimeFormatter); + if (!seenDateFormats.contains(dateTimeFormatter.format())) { + seenDateFormats.add(dateTimeFormatter.format()); + this.dateTimeFormatters.add(dateTimeFormatter); + } } return builder; } - public Builder dateTimeFormatter(FormatDateTimeFormatter[] dateTimeFormatters) { - this.dateTimeFormatters.addAll(newArrayList(dateTimeFormatters)); - return builder; - } - - public Builder dateTimeFormatter(FormatDateTimeFormatter dateTimeFormatter) { - this.dateTimeFormatters.add(dateTimeFormatter); - return builder; - } - public Builder add(DynamicTemplate dynamicTemplate) { this.dynamicTemplates.add(dynamicTemplate); return this;