Remove back compat layer with 2.x indices. (#26245)

As of 6.0 we do not need to support 2.x indices.
This commit is contained in:
Adrien Grand 2017-08-17 10:16:24 +02:00 committed by GitHub
parent d26c8b5c88
commit 15b7aeeb0f
10 changed files with 19 additions and 103 deletions

View File

@ -231,9 +231,7 @@ public class IndexTemplateMetaData extends AbstractDiffable<IndexTemplateMetaDat
IndexMetaData.Custom customIndexMetaData = IndexMetaData.lookupPrototypeSafe(type).readFrom(in);
builder.putCustom(type, customIndexMetaData);
}
if (in.getVersion().onOrAfter(Version.V_5_0_0_beta1)) {
builder.version(in.readOptionalVInt());
}
builder.version(in.readOptionalVInt());
return builder.build();
}
@ -265,9 +263,7 @@ public class IndexTemplateMetaData extends AbstractDiffable<IndexTemplateMetaDat
out.writeString(cursor.key);
cursor.value.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_5_0_0_beta1)) {
out.writeOptionalVInt(version);
}
out.writeOptionalVInt(version);
}
public static class Builder {

View File

@ -557,20 +557,7 @@ public final class AnalysisRegistry implements Closeable {
// TODO: remove alias support completely when we no longer support pre 5.0 indices
final String analyzerAliasKey = "index.analysis.analyzer." + analyzerFactory.name() + ".alias";
if (indexSettings.getSettings().get(analyzerAliasKey) != null) {
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_0_0_beta1)) {
// do not allow alias creation if the index was created on or after v5.0 alpha6
throw new IllegalArgumentException("setting [" + analyzerAliasKey + "] is not supported");
}
// the setting is now removed but we only support it for loading indices created before v5.0
deprecationLogger.deprecated("setting [{}] is only allowed on index [{}] because it was created before 5.x; " +
"analyzer aliases can no longer be created on new indices.", analyzerAliasKey, indexSettings.getIndex().getName());
Set<String> aliases = Sets.newHashSet(indexSettings.getSettings().getAsArray(analyzerAliasKey));
for (String alias : aliases) {
if (analyzerAliases.putIfAbsent(alias, analyzer) != null) {
throw new IllegalStateException("alias [" + alias + "] is already used by [" + analyzerAliases.get(alias).name() + "]");
}
}
throw new IllegalArgumentException("setting [" + analyzerAliasKey + "] is not supported");
}
}

View File

@ -186,7 +186,7 @@ public class DynamicTemplate implements ToXContentObject {
matchPattern = entry.getValue().toString();
} else if ("mapping".equals(propName)) {
mapping = (Map<String, Object>) entry.getValue();
} else if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha1)) {
} else {
// unknown parameters were ignored before but still carried through serialization
// so we need to ignore them at parsing time for old indices
throw new IllegalArgumentException("Illegal dynamic template parameter: [" + propName + "]");

View File

@ -212,19 +212,11 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
}
protected boolean defaultDocValues(Version indexCreated) {
if (indexCreated.onOrAfter(Version.V_5_0_0_alpha1)) {
// add doc values by default to keyword (boolean, numerics, etc.) fields
return fieldType.tokenized() == false;
} else {
return fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE;
}
return fieldType.tokenized() == false;
}
protected void setupFieldType(BuilderContext context) {
fieldType.setName(buildFullName(context));
if (context.indexCreatedVersion().before(Version.V_5_0_0_alpha1)) {
fieldType.setOmitNorms(fieldType.omitNorms() && fieldType.boost() == 1.0f);
}
if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) {
fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER);
@ -247,10 +239,8 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
super(simpleName);
assert indexSettings != null;
this.indexCreatedVersion = Version.indexCreated(indexSettings);
if (indexCreatedVersion.onOrAfter(Version.V_5_0_0_beta1)) {
if (simpleName.isEmpty()) {
throw new IllegalArgumentException("name cannot be empty string");
}
if (simpleName.isEmpty()) {
throw new IllegalArgumentException("name cannot be empty string");
}
fieldType.freeze();
this.fieldType = fieldType;

View File

@ -77,10 +77,7 @@ public class IndexFieldMapper extends MetadataFieldMapper {
public static class TypeParser implements MetadataFieldMapper.TypeParser {
@Override
public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
if (parserContext.indexVersionCreated().onOrAfter(Version.V_5_0_0_alpha3)) {
throw new MapperParsingException(NAME + " is not configurable");
}
return new Builder(parserContext.mapperService().fullName(NAME));
throw new MapperParsingException(NAME + " is not configurable");
}
@Override

View File

@ -321,11 +321,8 @@ public class ObjectMapper extends Mapper implements Cloneable {
Boolean includeInAll, Map<String, Mapper> mappers, Settings settings) {
super(name);
assert settings != null;
Version indexCreatedVersion = Version.indexCreated(settings);
if (indexCreatedVersion.onOrAfter(Version.V_5_0_0_beta1)) {
if (name.isEmpty()) {
throw new IllegalArgumentException("name cannot be empty string");
}
if (name.isEmpty()) {
throw new IllegalArgumentException("name cannot be empty string");
}
this.fullPath = fullPath;
this.enabled = enabled;

View File

@ -116,9 +116,6 @@ public class SourceFieldMapper extends MetadataFieldMapper {
if (fieldName.equals("enabled")) {
builder.enabled(TypeParsers.nodeBooleanValue(name, "enabled", fieldNode, parserContext));
iterator.remove();
} else if ("format".equals(fieldName) && parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1)) {
// ignore on old indices, reject on and after 5.0
iterator.remove();
} else if (fieldName.equals("includes")) {
List<Object> values = (List<Object>) fieldNode;
String[] includes = new String[values.size()];

View File

@ -27,7 +27,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.index.query.QueryShardContext;
@ -51,12 +50,11 @@ abstract class TermBasedFieldType extends MappedFieldType {
@Override
public Query termQuery(Object value, QueryShardContext context) {
failIfNotIndexed();
TermQuery query = new TermQuery(new Term(name(), indexedValueForSearch(value)));
if (boost() == 1f ||
(context != null && context.indexVersionCreated().before(Version.V_5_0_0_alpha1))) {
return query;
Query query = new TermQuery(new Term(name(), indexedValueForSearch(value)));
if (boost() != 1f) {
query = new BoostQuery(query, boost());
}
return new BoostQuery(query, boost());
return query;
}
@Override

View File

@ -35,11 +35,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.isArray;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeFloatValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMapValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue;
public class TypeParsers {
@ -158,37 +156,9 @@ public class TypeParsers {
}
}
public static boolean parseNorms(FieldMapper.Builder builder, String fieldName, String propName, Object propNode,
public static void parseNorms(FieldMapper.Builder builder, String fieldName, Object propNode,
Mapper.TypeParser.ParserContext parserContext) {
if (propName.equals("norms")) {
if (propNode instanceof Map) {
final Map<String, Object> properties = nodeMapValue(propNode, "norms");
for (Iterator<Entry<String, Object>> propsIterator = properties.entrySet().iterator(); propsIterator.hasNext(); ) {
Entry<String, Object> entry2 = propsIterator.next();
final String propName2 = entry2.getKey();
final Object propNode2 = entry2.getValue();
if (propName2.equals("enabled")) {
builder.omitNorms(nodeBooleanValue(fieldName, "enabled", propNode2, parserContext) == false);
propsIterator.remove();
} else if (propName2.equals("loading")) {
// ignore for bw compat
propsIterator.remove();
}
}
DocumentMapperParser.checkNoRemainingFields(propName, properties, parserContext.indexVersionCreated());
DEPRECATION_LOGGER.deprecated("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use " +
"[norms:true/false] instead");
} else {
builder.omitNorms(nodeBooleanValue(fieldName,"norms", propNode, parserContext) == false);
}
return true;
} else if (propName.equals("omit_norms")) {
builder.omitNorms(nodeBooleanValue(fieldName,"norms", propNode, parserContext));
DEPRECATION_LOGGER.deprecated("[omit_norms] is deprecated, please use [norms] instead with the opposite boolean value");
return true;
} else {
return false;
}
builder.omitNorms(nodeBooleanValue(fieldName, "norms", propNode, parserContext) == false);
}
/**
@ -203,7 +173,8 @@ public class TypeParsers {
Map.Entry<String, Object> entry = iterator.next();
final String propName = entry.getKey();
final Object propNode = entry.getValue();
if (parseNorms(builder, name, propName, propNode, parserContext)) {
if ("norms".equals(propName)) {
parseNorms(builder, name, propNode, parserContext);
iterator.remove();
}
}
@ -237,9 +208,6 @@ public class TypeParsers {
} else if (propName.equals("boost")) {
builder.boost(nodeFloatValue(propNode));
iterator.remove();
} else if (parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1)
&& parseNorms(builder, name, propName, propNode, parserContext)) {
iterator.remove();
} else if (propName.equals("index_options")) {
builder.indexOptions(nodeIndexOptionValue(propNode));
iterator.remove();
@ -259,11 +227,6 @@ public class TypeParsers {
SimilarityProvider similarityProvider = resolveSimilarity(parserContext, name, propNode.toString());
builder.similarity(similarityProvider);
iterator.remove();
} else if (propName.equals("fielddata")
&& propNode instanceof Map
&& parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1)) {
// ignore for bw compat
iterator.remove();
} else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
iterator.remove();
} else if (propName.equals("copy_to")) {
@ -387,10 +350,6 @@ public class TypeParsers {
}
private static SimilarityProvider resolveSimilarity(Mapper.TypeParser.ParserContext parserContext, String name, String value) {
if (parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha1) && "default".equals(value)) {
// "default" similarity has been renamed into "classic" in 3.x.
value = "classic";
}
SimilarityProvider similarityProvider = parserContext.getSimilarity(value);
if (similarityProvider == null) {
throw new MapperParsingException("Unknown Similarity type [" + value + "] for field [" + name + "]");

View File

@ -79,8 +79,7 @@ public final class SimilarityService extends AbstractIndexComponent {
Map<String, Settings> similaritySettings = this.indexSettings.getSettings().getGroups(IndexModule.SIMILARITY_SETTINGS_PREFIX);
for (Map.Entry<String, Settings> entry : similaritySettings.entrySet()) {
String name = entry.getKey();
// Starting with v5.0 indices, it should no longer be possible to redefine built-in similarities
if(BUILT_IN.containsKey(name) && indexSettings.getIndexVersionCreated().onOrAfter(Version.V_5_0_0_alpha1)) {
if (BUILT_IN.containsKey(name)) {
throw new IllegalArgumentException("Cannot redefine built-in Similarity [" + name + "]");
}
Settings providerSettings = entry.getValue();
@ -97,10 +96,6 @@ public final class SimilarityService extends AbstractIndexComponent {
Map<String, SimilarityProvider> providerMapping = addSimilarities(similaritySettings, indexSettings.getSettings(), scriptService,
DEFAULTS);
for (Map.Entry<String, SimilarityProvider> entry : providerMapping.entrySet()) {
// Avoid overwriting custom providers for indices older that v5.0
if (providers.containsKey(entry.getKey()) && indexSettings.getIndexVersionCreated().before(Version.V_5_0_0_alpha1)) {
continue;
}
providers.put(entry.getKey(), entry.getValue());
}
this.similarities = providers;