Remove bw compat from murmur3 mapper

This commit is contained in:
Simon Willnauer 2016-03-07 12:44:53 +01:00
parent 7e4c4cd8d9
commit f96900013c
2 changed files with 8 additions and 55 deletions

View File

@ -72,12 +72,10 @@ public class Murmur3FieldMapper extends LongFieldMapper {
@Override @Override
protected void setupFieldType(BuilderContext context) { protected void setupFieldType(BuilderContext context) {
super.setupFieldType(context); super.setupFieldType(context);
if (context.indexCreatedVersion().onOrAfter(Version.V_2_0_0_beta1)) { fieldType.setIndexOptions(IndexOptions.NONE);
fieldType.setIndexOptions(IndexOptions.NONE); defaultFieldType.setIndexOptions(IndexOptions.NONE);
defaultFieldType.setIndexOptions(IndexOptions.NONE); fieldType.setHasDocValues(true);
fieldType.setHasDocValues(true); defaultFieldType.setHasDocValues(true);
defaultFieldType.setHasDocValues(true);
}
} }
@Override @Override
@ -97,17 +95,11 @@ public class Murmur3FieldMapper extends LongFieldMapper {
Builder builder = new Builder(name); Builder builder = new Builder(name);
// tweaking these settings is no longer allowed, the entire purpose of murmur3 fields is to store a hash // tweaking these settings is no longer allowed, the entire purpose of murmur3 fields is to store a hash
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) { if (node.get("doc_values") != null) {
if (node.get("doc_values") != null) { throw new MapperParsingException("Setting [doc_values] cannot be modified for field [" + name + "]");
throw new MapperParsingException("Setting [doc_values] cannot be modified for field [" + name + "]");
}
if (node.get("index") != null) {
throw new MapperParsingException("Setting [index] cannot be modified for field [" + name + "]");
}
} }
if (node.get("index") != null) {
if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) { throw new MapperParsingException("Setting [index] cannot be modified for field [" + name + "]");
builder.indexOptions(IndexOptions.DOCS);
} }
parseNumberField(builder, name, node, parserContext); parseNumberField(builder, name, node, parserContext);

View File

@ -44,11 +44,6 @@ import java.util.Collections;
public class Murmur3FieldMapperTests extends ESSingleNodeTestCase { public class Murmur3FieldMapperTests extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class);
}
MapperRegistry mapperRegistry; MapperRegistry mapperRegistry;
IndexService indexService; IndexService indexService;
DocumentMapperParser parser; DocumentMapperParser parser;
@ -131,38 +126,4 @@ public class Murmur3FieldMapperTests extends ESSingleNodeTestCase {
assertTrue(e.getMessage().contains("Setting [index] cannot be modified")); assertTrue(e.getMessage().contains("Setting [index] cannot be modified"));
} }
} }
public void testDocValuesSettingBackcompat() throws Exception {
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
indexService = createIndex("test_bwc", settings);
parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(),
indexService.analysisService(), indexService.similarityService(), mapperRegistry, indexService::newQueryShardContext);
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "murmur3")
.field("doc_values", false)
.endObject().endObject().endObject().endObject().string();
DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping));
Murmur3FieldMapper mapper = (Murmur3FieldMapper)docMapper.mappers().getMapper("field");
assertFalse(mapper.fieldType().hasDocValues());
}
public void testIndexSettingBackcompat() throws Exception {
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
indexService = createIndex("test_bwc", settings);
parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(),
indexService.analysisService(), indexService.similarityService(), mapperRegistry, indexService::newQueryShardContext);
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "murmur3")
.field("index", "not_analyzed")
.endObject().endObject().endObject().endObject().string();
DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping));
Murmur3FieldMapper mapper = (Murmur3FieldMapper)docMapper.mappers().getMapper("field");
assertEquals(IndexOptions.DOCS, mapper.fieldType().indexOptions());
}
// TODO: add more tests
} }