Skip to content

Commit

Permalink
Unused boost parameter should not throw mapping exception (#64999) (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
romseygeek committed Nov 12, 2020
1 parent d9970fa commit caf143f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ protected IndexAnalyzers createIndexAnalyzers(IndexSettings indexSettings) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public final void parse(String name, ParserContext parserContext, Map<String, Ob
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected Set<String> unsupportedProperties() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ protected Set<String> unsupportedProperties() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,26 @@ public void testMeta() throws IOException {
);
}

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

/**
Expand Down

0 comments on commit caf143f

Please sign in to comment.