Unused boost parameter should not throw mapping exception (#64999) (#65014)

We were correctly dealing with boosts that had an effect, but mappers
that had a silently accepted but ignored boost parameter were throwing
an error instead of continuing to ignore the boost but emitting a
warning.

Fixes #64982
This commit is contained in:
Alan Woodward 2020-11-12 19:28:32 +00:00 committed by GitHub
parent d9970fa764
commit caf143f4a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 14 deletions

View File

@ -94,6 +94,11 @@ public class TokenCountFieldMapperTests extends MapperTestCase {
return new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap());
}
@Override
protected String typeName() {
return "token_count";
}
/**
* When position increments are counted, we're looking to make sure that we:
- don't count tokens without an increment

View File

@ -634,7 +634,7 @@ public abstract class ParametrizedFieldMapper extends FieldMapper {
// made no sense; if we've got here, that means that they're not declared on a current mapper,
// and so we emit a deprecation warning rather than failing a previously working mapping.
private static final Set<String> DEPRECATED_PARAMS
= new HashSet<>(Arrays.asList("store", "meta", "index", "doc_values", "index_options", "similarity"));
= new HashSet<>(Arrays.asList("store", "meta", "boost", "index", "doc_values", "index_options", "similarity"));
private static boolean isDeprecatedParameter(String propName, Version indexCreatedVersion) {
return DEPRECATED_PARAMS.contains(propName);

View File

@ -45,6 +45,11 @@ public class GeoShapeFieldMapperTests extends FieldMapperTestCase2<GeoShapeField
return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store");
}
@Override
protected boolean supportsOrIgnoresBoost() {
return false;
}
@Override
protected GeoShapeFieldMapper.Builder newBuilder() {
return new GeoShapeFieldMapper.Builder("geoshape");

View File

@ -69,6 +69,11 @@ public class LegacyGeoShapeFieldMapperTests extends FieldMapperTestCase2<LegacyG
return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store");
}
@Override
protected boolean supportsOrIgnoresBoost() {
return false;
}
@Override
protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "geo_shape").field("strategy", "recursive");

View File

@ -246,20 +246,26 @@ public abstract class MapperTestCase extends MapperServiceTestCase {
);
}
protected String typeName() throws IOException {
MapperService ms = createMapperService(fieldMapping(this::minimalMapping));
return ms.fieldType("field").typeName();
}
protected boolean supportsOrIgnoresBoost() {
return true;
}
public final void testDeprecatedBoost() throws IOException {
try {
createMapperService(fieldMapping(b -> {
minimalMapping(b);
b.field("boost", 2.0);
}));
assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0");
}
catch (MapperParsingException e) {
assertThat(e.getMessage(), anyOf(
containsString("unknown parameter [boost]"),
containsString("[boost : 2.0]")));
}
assertParseMinimalWarnings();
assumeTrue("Does not support [boost] parameter", supportsOrIgnoresBoost());
createMapperService(fieldMapping(b -> {
minimalMapping(b);
b.field("boost", 2.0);
}));
String type = typeName();
String[] warnings = new String[] {
"Parameter [boost] on field [field] is deprecated and will be removed in 8.0",
"Parameter [boost] has no effect on type [" + type + "] and will be removed in future" };
allowedWarnings(warnings);
}
/**