parent
e074e00f76
commit
bc20f068c9
|
@ -278,7 +278,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
||||||
protected float boost;
|
protected float boost;
|
||||||
protected final FieldType fieldType;
|
protected final FieldType fieldType;
|
||||||
protected final NamedAnalyzer indexAnalyzer;
|
protected final NamedAnalyzer indexAnalyzer;
|
||||||
protected final NamedAnalyzer searchAnalyzer;
|
protected NamedAnalyzer searchAnalyzer;
|
||||||
protected PostingsFormatProvider postingsFormat;
|
protected PostingsFormatProvider postingsFormat;
|
||||||
protected final SimilarityProvider similarity;
|
protected final SimilarityProvider similarity;
|
||||||
|
|
||||||
|
@ -557,15 +557,6 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
||||||
} else if (!this.indexAnalyzer.name().equals(fieldMergeWith.indexAnalyzer.name())) {
|
} else if (!this.indexAnalyzer.name().equals(fieldMergeWith.indexAnalyzer.name())) {
|
||||||
mergeContext.addConflict("mapper [" + names.fullName() + "] has different index_analyzer");
|
mergeContext.addConflict("mapper [" + names.fullName() + "] has different index_analyzer");
|
||||||
}
|
}
|
||||||
if (this.searchAnalyzer == null) {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.similarity == null) {
|
if (this.similarity == null) {
|
||||||
if (fieldMergeWith.similarity() != null) {
|
if (fieldMergeWith.similarity() != null) {
|
||||||
|
@ -583,6 +574,9 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
||||||
if (fieldMergeWith.postingsFormat != null) {
|
if (fieldMergeWith.postingsFormat != null) {
|
||||||
this.postingsFormat = fieldMergeWith.postingsFormat;
|
this.postingsFormat = fieldMergeWith.postingsFormat;
|
||||||
}
|
}
|
||||||
|
if (fieldMergeWith.searchAnalyzer != null) {
|
||||||
|
this.searchAnalyzer = fieldMergeWith.searchAnalyzer;
|
||||||
|
}
|
||||||
if (fieldMergeWith.customFieldDataSettings != null) {
|
if (fieldMergeWith.customFieldDataSettings != null) {
|
||||||
if (!Objects.equal(fieldMergeWith.customFieldDataSettings, this.customFieldDataSettings)) {
|
if (!Objects.equal(fieldMergeWith.customFieldDataSettings, this.customFieldDataSettings)) {
|
||||||
this.customFieldDataSettings = fieldMergeWith.customFieldDataSettings;
|
this.customFieldDataSettings = fieldMergeWith.customFieldDataSettings;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.test.unit.index.mapper.merge;
|
package org.elasticsearch.test.unit.index.mapper.merge;
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -83,4 +84,44 @@ public class TestMergeMapperTests {
|
||||||
assertThat(mergeResult.conflicts().length, equalTo(1));
|
assertThat(mergeResult.conflicts().length, equalTo(1));
|
||||||
assertThat(mergeResult.conflicts()[0], equalTo("object mapping [obj] can't be changed from nested to non-nested"));
|
assertThat(mergeResult.conflicts()[0], equalTo("object mapping [obj] can't be changed from nested to non-nested"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeSearchAnalyzer() throws Exception {
|
||||||
|
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "whitespace").endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "keyword").endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
DocumentMapper existing = MapperTests.newParser().parse(mapping1);
|
||||||
|
DocumentMapper changed = MapperTests.newParser().parse(mapping2);
|
||||||
|
|
||||||
|
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
|
||||||
|
DocumentMapper.MergeResult mergeResult = existing.merge(changed, mergeFlags().simulate(false));
|
||||||
|
|
||||||
|
assertThat(mergeResult.hasConflicts(), equalTo(false));
|
||||||
|
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("keyword"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNotChangeSearchAnalyzer() throws Exception {
|
||||||
|
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "whitespace").endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("field").field("type", "string").field("postings_format", "direct").endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
DocumentMapper existing = MapperTests.newParser().parse(mapping1);
|
||||||
|
DocumentMapper changed = MapperTests.newParser().parse(mapping2);
|
||||||
|
|
||||||
|
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
|
||||||
|
DocumentMapper.MergeResult mergeResult = existing.merge(changed, mergeFlags().simulate(false));
|
||||||
|
|
||||||
|
assertThat(mergeResult.hasConflicts(), equalTo(false));
|
||||||
|
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
|
||||||
|
assertThat((existing.mappers().name("field").mapper().postingsFormatProvider()).name(), equalTo("direct"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue