Fix MapperService.allEnabled(). (#22227)
It returns whether the last merged mapping has `_all` enabled rather than whether any of the types has `_all` enabled.
This commit is contained in:
parent
96f1739c0d
commit
1ed2e18ded
|
@ -153,7 +153,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns true if the "_all" field is enabled for the type
|
||||
* Returns true if the "_all" field is enabled on any type.
|
||||
*/
|
||||
public boolean allEnabled() {
|
||||
return this.allEnabled;
|
||||
|
@ -377,7 +377,9 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|||
this.hasNested = hasNested;
|
||||
this.fullPathObjectMappers = fullPathObjectMappers;
|
||||
this.parentTypes = parentTypes;
|
||||
this.allEnabled = mapper.allFieldMapper().enabled();
|
||||
// this is only correct because types cannot be removed and we do not
|
||||
// allow to disable an existing _all field
|
||||
this.allEnabled |= mapper.allFieldMapper().enabled();
|
||||
|
||||
assert assertSerialization(newMapper);
|
||||
assert assertMappersShareSameFieldType();
|
||||
|
|
|
@ -215,4 +215,31 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
|
|||
indexService.mapperService().merge("type3", normsDisabledMapping, MergeReason.MAPPING_UPDATE, true);
|
||||
assertNotSame(indexService.mapperService().documentMapper("type1"), documentMapper);
|
||||
}
|
||||
|
||||
public void testAllEnabled() throws Exception {
|
||||
IndexService indexService = createIndex("test");
|
||||
assertFalse(indexService.mapperService().allEnabled());
|
||||
|
||||
CompressedXContent enabledAll = new CompressedXContent(XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("_all")
|
||||
.field("enabled", true)
|
||||
.endObject().endObject().bytes());
|
||||
|
||||
CompressedXContent disabledAll = new CompressedXContent(XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("_all")
|
||||
.field("enabled", false)
|
||||
.endObject().endObject().bytes());
|
||||
|
||||
indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, enabledAll,
|
||||
MergeReason.MAPPING_UPDATE, random().nextBoolean());
|
||||
assertFalse(indexService.mapperService().allEnabled()); // _default_ does not count
|
||||
|
||||
indexService.mapperService().merge("some_type", enabledAll,
|
||||
MergeReason.MAPPING_UPDATE, random().nextBoolean());
|
||||
assertTrue(indexService.mapperService().allEnabled());
|
||||
|
||||
indexService.mapperService().merge("other_type", disabledAll,
|
||||
MergeReason.MAPPING_UPDATE, random().nextBoolean());
|
||||
assertTrue(indexService.mapperService().allEnabled()); // this returns true if any of the types has _all enabled
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue