public void testMergingMappings() throws Exception { String enabledMapping = XContentFactory.jsonBuilder() .startObject() .startObject("type") .startObject("_field_names") .field("enabled", true) .endObject() .endObject() .endObject() .string(); String disabledMapping = XContentFactory.jsonBuilder() .startObject() .startObject("type") .startObject("_field_names") .field("enabled", false) .endObject() .endObject() .endObject() .string(); DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); DocumentMapper mapperEnabled = parser.parse(enabledMapping); DocumentMapper mapperDisabled = parser.parse(disabledMapping); mapperEnabled.merge(mapperDisabled, DocumentMapper.MergeFlags.mergeFlags().simulate(false)); assertFalse(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).enabled()); mapperEnabled = parser.parse(enabledMapping); mapperDisabled.merge(mapperEnabled, DocumentMapper.MergeFlags.mergeFlags().simulate(false)); assertTrue(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).enabled()); }
@Test public void testThatDisablingWorksWhenMerging() throws Exception { String enabledMapping = XContentFactory.jsonBuilder() .startObject() .startObject("type") .startObject("_size") .field("enabled", true) .endObject() .endObject() .endObject() .string(); DocumentMapper enabledMapper = MapperTests.newParser().parse(enabledMapping); String disabledMapping = XContentFactory.jsonBuilder() .startObject() .startObject("type") .startObject("_size") .field("enabled", false) .endObject() .endObject() .endObject() .string(); DocumentMapper disabledMapper = MapperTests.newParser().parse(disabledMapping); enabledMapper.merge(disabledMapper, DocumentMapper.MergeFlags.mergeFlags().simulate(false)); assertThat(enabledMapper.SizeFieldMapper().enabled(), is(false)); }
private void testNoConflictWhileMergingAndMappingChanged( XContentBuilder mapping, XContentBuilder mappingUpdate, XContentBuilder expectedMapping) throws IOException { IndexService indexService = createIndex("test", ImmutableSettings.settingsBuilder().build(), "type", mapping); // simulate like in MetaDataMappingService#putMapping DocumentMapper.MergeResult mergeResult = indexService .mapperService() .documentMapper("type") .merge( indexService .mapperService() .parse("type", new CompressedString(mappingUpdate.bytes()), true), DocumentMapper.MergeFlags.mergeFlags().simulate(false)); // assure we have no conflicts assertThat(mergeResult.conflicts().length, equalTo(0)); // make sure mappings applied CompressedString mappingAfterUpdate = indexService.mapperService().documentMapper("type").mappingSource(); assertThat(mappingAfterUpdate.toString(), equalTo(expectedMapping.string())); }
protected void testConflictWhileMergingAndMappingUnchanged( XContentBuilder mapping, XContentBuilder mappingUpdate) throws IOException { IndexService indexService = createIndex("test", ImmutableSettings.settingsBuilder().build(), "type", mapping); CompressedString mappingBeforeUpdate = indexService.mapperService().documentMapper("type").mappingSource(); // simulate like in MetaDataMappingService#putMapping DocumentMapper.MergeResult mergeResult = indexService .mapperService() .documentMapper("type") .merge( indexService .mapperService() .parse("type", new CompressedString(mappingUpdate.bytes()), true), DocumentMapper.MergeFlags.mergeFlags().simulate(true)); // assure we have conflicts assertThat(mergeResult.conflicts().length, equalTo(1)); // make sure simulate flag actually worked - no mappings applied CompressedString mappingAfterUpdate = indexService.mapperService().documentMapper("type").mappingSource(); assertThat(mappingAfterUpdate, equalTo(mappingBeforeUpdate)); }