Skip to content

Commit d4e1add

Browse files
authored
Unused boost parameter should not throw mapping exception (#64999)
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
1 parent 98ee4f6 commit d4e1add

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ protected IndexAnalyzers createIndexAnalyzers(IndexSettings indexSettings) {
9999
return new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap());
100100
}
101101

102+
@Override
103+
protected String typeName() {
104+
return "token_count";
105+
}
106+
102107
/**
103108
* When position increments are counted, we're looking to make sure that we:
104109
- don't count tokens without an increment

server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ public final void parse(String name, ParserContext parserContext, Map<String, Ob
10141014
// made no sense; if we've got here, that means that they're not declared on a current mapper,
10151015
// and so we emit a deprecation warning rather than failing a previously working mapping.
10161016
private static final Set<String> DEPRECATED_PARAMS
1017-
= new HashSet<>(Arrays.asList("store", "meta", "index", "doc_values", "index_options", "similarity"));
1017+
= new HashSet<>(Arrays.asList("store", "meta", "index", "doc_values", "index_options", "similarity", "boost"));
10181018

10191019
private static boolean isDeprecatedParameter(String propName, Version indexCreatedVersion) {
10201020
return DEPRECATED_PARAMS.contains(propName);

test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,21 @@ public void testMeta() throws IOException {
271271
);
272272
}
273273

274+
protected String typeName() throws IOException {
275+
MapperService ms = createMapperService(fieldMapping(this::minimalMapping));
276+
return ms.fieldType("field").typeName();
277+
}
278+
274279
public final void testDeprecatedBoost() throws IOException {
275-
try {
276-
createMapperService(fieldMapping(b -> {
277-
minimalMapping(b);
278-
b.field("boost", 2.0);
279-
}));
280-
String[] warnings = Strings.concatStringArrays(getParseMinimalWarnings(),
281-
new String[]{"Parameter [boost] on field [field] is deprecated and will be removed in 8.0"});
282-
assertWarnings(warnings);
283-
} catch (MapperParsingException e) {
284-
assertThat(e.getMessage(), anyOf(
285-
containsString("unknown parameter [boost]"),
286-
containsString("[boost : 2.0]")));
287-
}
288-
assertParseMinimalWarnings();
280+
MapperService ms = createMapperService(fieldMapping(b -> {
281+
minimalMapping(b);
282+
b.field("boost", 2.0);
283+
}));
284+
String type = typeName();
285+
String[] warnings = Strings.concatStringArrays(getParseMinimalWarnings(),
286+
new String[]{"Parameter [boost] on field [field] is deprecated and will be removed in 8.0",
287+
"Parameter [boost] has no effect on type [" + type + "] and will be removed in future"});
288+
allowedWarnings(warnings);
289289
}
290290

291291
/**

0 commit comments

Comments
 (0)