Skip to content

Commit

Permalink
Remove support for type, fields, copy_to and boost in metadata field …
Browse files Browse the repository at this point in the history
…definition (elastic#116944)

Support for type, fields, copy_to and boost in metadata field definition has been
deprecated in elastic#90989. Such fields have been long parsed and silently ignored.
  • Loading branch information
javanna authored and alexey-ivanov-es committed Nov 28, 2024
1 parent 00e180a commit e511bd2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 68 deletions.
11 changes: 11 additions & 0 deletions docs/changelog/116944.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pr: 116944
summary: "Remove support for type, fields, `copy_to` and boost in metadata field definition"
area: Mapping
type: breaking
issues: []
breaking:
title: "Remove support for type, fields, copy_to and boost in metadata field definition"
area: Mapping
details: The type, fields, copy_to and boost parameters are no longer supported in metadata field definition
impact: Users providing type, fields, copy_to or boost as part of metadata field definition should remove them from their mappings.
notable: false
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
package org.elasticsearch.index.mapper;

import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
Expand Down Expand Up @@ -135,8 +132,6 @@ public final MetadataFieldMapper build(MapperBuilderContext context) {
return build();
}

private static final Set<String> UNSUPPORTED_PARAMETERS_8_6_0 = Set.of("type", "fields", "copy_to", "boost");

public final void parseMetadataField(String name, MappingParserContext parserContext, Map<String, Object> fieldNode) {
final Parameter<?>[] params = getParameters();
Map<String, Parameter<?>> paramsMap = Maps.newHashMapWithExpectedSize(params.length);
Expand All @@ -149,20 +144,6 @@ public final void parseMetadataField(String name, MappingParserContext parserCon
final Object propNode = entry.getValue();
Parameter<?> parameter = paramsMap.get(propName);
if (parameter == null) {
if (UNSUPPORTED_PARAMETERS_8_6_0.contains(propName)) {
if (parserContext.indexVersionCreated().onOrAfter(IndexVersions.V_8_6_0)) {
// silently ignore type, and a few other parameters: sadly we've been doing this for a long time
deprecationLogger.warn(
DeprecationCategory.API,
propName,
"Parameter [{}] has no effect on metadata field [{}] and will be removed in future",
propName,
name
);
}
iterator.remove();
continue;
}
throw new MapperParsingException("unknown parameter [" + propName + "] on metadata field [" + name + "]");
}
parameter.parse(name, parserContext, propNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -142,52 +141,4 @@ public final void testFixedMetaFieldsAreNotConfigurable() throws IOException {
);
assertEquals("Failed to parse mapping: " + fieldName() + " is not configurable", exception.getMessage());
}

public void testTypeAndFriendsAreSilentlyIgnoredBefore_8_6_0() throws IOException {
assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
IndexVersion previousVersion = IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_6_0);
IndexVersion version = IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, previousVersion);
assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
MapperService mapperService = createMapperService(version, mapping(b -> {}));
// these parameters were previously silently ignored, they will still be ignored in existing indices
String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" };
for (String param : unsupportedParameters) {
String mappingAsString = "{\n"
+ " \"_doc\" : {\n"
+ " \""
+ fieldName()
+ "\" : {\n"
+ " \""
+ param
+ "\" : \"any\"\n"
+ " }\n"
+ " }\n"
+ "}";
assertNotNull(mapperService.parseMapping("_doc", MergeReason.MAPPING_UPDATE, new CompressedXContent(mappingAsString)));
}
}

public void testTypeAndFriendsAreDeprecatedFrom_8_6_0() throws IOException {
assumeTrue("Metadata field " + fieldName() + " isn't configurable", isConfigurable());
IndexVersion version = IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_8_6_0, IndexVersion.current());
assumeTrue("Metadata field " + fieldName() + " is not supported on version " + version, isSupportedOn(version));
MapperService mapperService = createMapperService(version, mapping(b -> {}));
// these parameters were previously silently ignored, they are now deprecated in new indices
String[] unsupportedParameters = new String[] { "fields", "copy_to", "boost", "type" };
for (String param : unsupportedParameters) {
String mappingAsString = "{\n"
+ " \"_doc\" : {\n"
+ " \""
+ fieldName()
+ "\" : {\n"
+ " \""
+ param
+ "\" : \"any\"\n"
+ " }\n"
+ " }\n"
+ "}";
assertNotNull(mapperService.parseMapping("_doc", MergeReason.MAPPING_UPDATE, new CompressedXContent(mappingAsString)));
assertWarnings("Parameter [" + param + "] has no effect on metadata field [" + fieldName() + "] and will be removed in future");
}
}
}

0 comments on commit e511bd2

Please sign in to comment.