Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ public static IndexTemplateMetaData readFrom(StreamInput in) throws IOException
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();
}

Expand Down Expand Up @@ -265,9 +263,7 @@ public void writeTo(StreamOutput out) throws IOException {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,20 +557,7 @@ private void processAnalyzerFactory(DeprecationLogger deprecationLogger,
// 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static DynamicTemplate parse(String name, Map<String, Object> conf,
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 + "]");
Expand Down
16 changes: 3 additions & 13 deletions core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,11 @@ protected String buildFullName(BuilderContext context) {
}

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);
Expand All @@ -247,10 +239,8 @@ protected FieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldT
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ public IndexFieldMapper build(BuilderContext context) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,8 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map<Strin
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> n
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()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;

Expand All @@ -51,12 +50,11 @@ protected BytesRef indexedValueForSearch(Object value) {
@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
Expand Down
49 changes: 4 additions & 45 deletions core/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
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 {
Expand Down Expand Up @@ -158,37 +156,9 @@ private static void parseAnalyzersAndTermVectors(FieldMapper.Builder builder, St
}
}

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);
}

/**
Expand All @@ -203,7 +173,8 @@ public static void parseTextField(FieldMapper.Builder builder, String name, Map<
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();
}
}
Expand Down Expand Up @@ -237,9 +208,6 @@ public static void parseField(FieldMapper.Builder builder, String name, Map<Stri
} 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();
Expand All @@ -259,11 +227,6 @@ && parseNorms(builder, name, propName, propNode, parserContext)) {
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")) {
Expand Down Expand Up @@ -387,10 +350,6 @@ public static void parseCopyFields(Object propNode, FieldMapper.Builder builder)
}

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 + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public SimilarityService(IndexSettings indexSettings, ScriptService scriptServic
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();
Expand All @@ -97,10 +96,6 @@ public SimilarityService(IndexSettings indexSettings, ScriptService scriptServic
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;
Expand Down