From 9f6fde9adb6bd70bbe137ba076e345fa72b29128 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 15 Jul 2010 20:40:40 +0300 Subject: [PATCH] better handling of failed merge because of different types --- .../index/mapper/MergeMappingException.java | 2 +- .../index/mapper/xcontent/XContentFieldMapper.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java index 98acdb1d329..a3a3439eeb6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java @@ -29,7 +29,7 @@ public class MergeMappingException extends MapperException { private final String[] failures; public MergeMappingException(String[] failures) { - super("Merge failed with failures [" + Arrays.toString(failures) + "]"); + super("Merge failed with failures {" + Arrays.toString(failures) + "}"); this.failures = failures; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentFieldMapper.java index 5673afdb73b..5d0860746ce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentFieldMapper.java @@ -347,7 +347,13 @@ public abstract class XContentFieldMapper implements FieldMapper, XContent @Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException { if (!this.getClass().equals(mergeWith.getClass())) { - mergeContext.addConflict("mapper [" + names.fullName() + "] of different type"); + String mergedType = mergeWith.getClass().getSimpleName(); + if (mergeWith instanceof XContentFieldMapper) { + mergedType = ((XContentFieldMapper) mergeWith).contentType(); + } + mergeContext.addConflict("mapper [" + names.fullName() + "] of different type, current_type [" + contentType() + "], merged_type [" + mergedType + "]"); + // different types, return + return; } XContentFieldMapper fieldMergeWith = (XContentFieldMapper) mergeWith; if (!this.index.equals(fieldMergeWith.index)) { @@ -363,6 +369,8 @@ public abstract class XContentFieldMapper implements FieldMapper, XContent if (fieldMergeWith.indexAnalyzer != null) { mergeContext.addConflict("mapper [" + names.fullName() + "] has different index_analyzer"); } + } else if (fieldMergeWith.indexAnalyzer == null) { + mergeContext.addConflict("mapper [" + names.fullName() + "] has different index_analyzer"); } else if (!this.indexAnalyzer.name().equals(fieldMergeWith.indexAnalyzer.name())) { mergeContext.addConflict("mapper [" + names.fullName() + "] has different index_analyzer"); } @@ -370,6 +378,8 @@ public abstract class XContentFieldMapper implements FieldMapper, XContent if (fieldMergeWith.searchAnalyzer != null) { mergeContext.addConflict("mapper [" + names.fullName() + "] has different search_analyzer"); } + } else if (fieldMergeWith.searchAnalyzer == null) { + mergeContext.addConflict("mapper [" + names.fullName() + "] has different search_analyzer"); } else if (!this.searchAnalyzer.name().equals(fieldMergeWith.searchAnalyzer.name())) { mergeContext.addConflict("mapper [" + names.fullName() + "] has different search_analyzer"); }