Fix includes/excludes to be handled on merge conflict checking when they

are null
This commit is contained in:
Ryan Ernst 2015-05-14 14:36:26 -07:00
parent d31ce43452
commit 0e14c6d256
2 changed files with 15 additions and 7 deletions

View File

@ -222,24 +222,24 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements Ro
this.enabled = enabled;
this.compress = compress;
this.compressThreshold = compressThreshold;
this.includes = includes;
this.excludes = excludes;
this.includes = includes == null ? Strings.EMPTY_ARRAY : includes;
this.excludes = excludes == null ? Strings.EMPTY_ARRAY : excludes;
this.format = format;
this.formatContentType = format == null ? null : XContentType.fromRestContentType(format);
this.complete = enabled && includes == null && excludes == null;
}
public boolean enabled() {
return this.enabled;
return enabled;
}
public String[] excludes() {
return this.excludes != null ? this.excludes : Strings.EMPTY_ARRAY;
return excludes;
}
public String[] includes() {
return this.includes != null ? this.includes : Strings.EMPTY_ARRAY;
return includes;
}
public boolean isComplete() {
@ -433,10 +433,10 @@ public class SourceFieldMapper extends AbstractFieldMapper<byte[]> implements Ro
if (this.enabled != sourceMergeWith.enabled) {
mergeResult.addConflict("Cannot update enabled setting for [_source]");
}
if (Arrays.equals(this.includes, sourceMergeWith.includes) == false) {
if (Arrays.equals(includes, sourceMergeWith.includes) == false) {
mergeResult.addConflict("Cannot update includes setting for [_source]");
}
if (Arrays.equals(this.excludes, sourceMergeWith.excludes) == false) {
if (Arrays.equals(excludes, sourceMergeWith.excludes) == false) {
mergeResult.addConflict("Cannot update excludes setting for [_source]");
}
} else {

View File

@ -253,9 +253,13 @@ public class DefaultSourceMappingTests extends ElasticsearchSingleNodeTest {
public void testIncludesNotUpdateable() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_source").array("includes", "foo.*").endObject()
.endObject().endObject().string();
assertConflicts(defaultMapping, mapping1, parser, "Cannot update includes setting for [_source]");
assertConflicts(mapping1, defaultMapping, parser, "Cannot update includes setting for [_source]");
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_source").array("includes", "foo.*", "bar.*").endObject()
.endObject().endObject().string();
@ -267,9 +271,13 @@ public class DefaultSourceMappingTests extends ElasticsearchSingleNodeTest {
public void testExcludesNotUpdateable() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_source").array("excludes", "foo.*").endObject()
.endObject().endObject().string();
assertConflicts(defaultMapping, mapping1, parser, "Cannot update excludes setting for [_source]");
assertConflicts(mapping1, defaultMapping, parser, "Cannot update excludes setting for [_source]");
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_source").array("excludes", "foo.*", "bar.*").endObject()
.endObject().endObject().string();