better handling of failed merge because of different types

This commit is contained in:
kimchy 2010-07-15 20:40:40 +03:00
parent cfa56cb3d6
commit 9f6fde9adb
2 changed files with 12 additions and 2 deletions

View File

@ -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;
}

View File

@ -347,7 +347,13 @@ public abstract class XContentFieldMapper<T> implements FieldMapper<T>, 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<T> implements FieldMapper<T>, 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<T> implements FieldMapper<T>, 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");
}