fix field names to be disabled again pre 1.3

This commit is contained in:
Ryan Ernst 2015-06-09 11:41:27 -07:00
parent b0466bbacd
commit 9d57818cee
2 changed files with 11 additions and 10 deletions

View File

@ -187,6 +187,11 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
super(fieldType, false, fieldDataSettings, indexSettings);
this.defaultFieldType = Defaults.FIELD_TYPE;
this.pre13Index = Version.indexCreated(indexSettings).before(Version.V_1_3_0);
if (this.pre13Index) {
this.fieldType = this.fieldType.clone();
fieldType().setEnabled(false);
this.fieldType.freeze();
}
}
@Override
@ -194,10 +199,6 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
return (FieldNamesFieldType)fieldType;
}
public boolean enabled() {
return pre13Index == false && fieldType().isEnabled();
}
@Override
public MappedFieldType defaultFieldType() {
return defaultFieldType;

View File

@ -98,7 +98,7 @@ public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldNamesFieldMapper fieldNamesMapper = docMapper.rootMapper(FieldNamesFieldMapper.class);
assertTrue(fieldNamesMapper.enabled());
assertTrue(fieldNamesMapper.fieldType().isEnabled());
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -115,7 +115,7 @@ public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
.endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldNamesFieldMapper fieldNamesMapper = docMapper.rootMapper(FieldNamesFieldMapper.class);
assertFalse(fieldNamesMapper.enabled());
assertFalse(fieldNamesMapper.fieldType().isEnabled());
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -131,7 +131,7 @@ public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_2_4.id).build();
DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse(mapping);
FieldNamesFieldMapper fieldNamesMapper = docMapper.rootMapper(FieldNamesFieldMapper.class);
assertFalse(fieldNamesMapper.enabled());
assertFalse(fieldNamesMapper.fieldType().isEnabled());
}
public void testDisablingBackcompat() throws Exception {
@ -143,7 +143,7 @@ public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse(mapping);
FieldNamesFieldMapper fieldNamesMapper = docMapper.rootMapper(FieldNamesFieldMapper.class);
assertFalse(fieldNamesMapper.enabled());
assertFalse(fieldNamesMapper.fieldType().isEnabled());
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -177,10 +177,10 @@ public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
DocumentMapper mapperEnabled = parser.parse(enabledMapping);
DocumentMapper mapperDisabled = parser.parse(disabledMapping);
mapperEnabled.merge(mapperDisabled.mapping(), false);
assertFalse(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).enabled());
assertFalse(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).fieldType().isEnabled());
mapperEnabled = parser.parse(enabledMapping);
mapperDisabled.merge(mapperEnabled.mapping(), false);
assertTrue(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).enabled());
assertTrue(mapperEnabled.rootMapper(FieldNamesFieldMapper.class).fieldType().isEnabled());
}
}