From 43ace5f80d78389eacfef40b340a896cf8108961 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 18 Sep 2020 15:34:54 +0100 Subject: [PATCH] Emit deprecation warnings when boosts are defined in mappings (#62623) We removed index-time boosting back in 5x, and we no longer document the 'boost' parameter on any of our mapping types. However, it is still possible to define an index-time boost on a field mapper for a surprisingly large number of field types, and they even have an effect (sometimes, on some queries). As a first step in finally removing all traces of index time boosting, this comment emits a deprecation warning whenever a boost parameter is found on a mapping definition. --- .../reference/migration/migrate_7_10.asciidoc | 15 ++++++++++++ .../index/mapper/ParametrizedFieldMapper.java | 6 +++++ .../index/mapper/TypeParsers.java | 4 ++++ .../index/mapper/BooleanFieldMapperTests.java | 6 +++++ .../index/mapper/DateFieldMapperTests.java | 5 ++++ .../index/mapper/KeywordFieldMapperTests.java | 6 +++++ .../index/mapper/RangeFieldMapperTests.java | 5 ++++ .../index/query/MatchQueryBuilderTests.java | 2 +- .../index/mapper/MapperTestCase.java | 23 ++++++++++++++++++- 9 files changed, 70 insertions(+), 2 deletions(-) diff --git a/docs/reference/migration/migrate_7_10.asciidoc b/docs/reference/migration/migrate_7_10.asciidoc index 5dccba087e7..284c2020264 100644 --- a/docs/reference/migration/migrate_7_10.asciidoc +++ b/docs/reference/migration/migrate_7_10.asciidoc @@ -54,3 +54,18 @@ deprecated starting 7.10.0 and will be removed in 8.0.0. *Impact* + Use the <>. ==== + +[[mapping-boosts]] +.The `boost` parameter on field mappings has been deprecated +[%collapsible] +==== +*Details* + +Index-time boosts have been deprecated since the 5x line, but it is still possible +to declare field-specific boosts in the mappings. This is now deprecated as well, +and will be removed entirely in 8.0. Mappings containing field boosts will continue +to work in 7.x but will emit a deprecation warning. + +*Impact* + +The `boost` setting should be removed from templates and mappings. Use boosts +directly on queries instead. +==== diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java index 5694e93539b..c915bbddfd1 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java @@ -571,6 +571,12 @@ public abstract class ParametrizedFieldMapper extends FieldMapper { throw new MapperParsingException("unknown parameter [" + propName + "] on mapper [" + name + "] of type [" + type + "]"); } + if (Objects.equals("boost", propName)) { + deprecationLogger.deprecate( + "boost", + "Parameter [boost] on field [{}] is deprecated and will be removed in 8.0", + name); + } if (propNode == null && parameter.acceptsNull == false) { throw new MapperParsingException("[" + propName + "] on mapper [" + name + "] of type [" + type + "] must not have a [null] value"); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java b/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java index 4100d25e338..fac927208f7 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java @@ -245,6 +245,10 @@ public class TypeParsers { iterator.remove(); } else if (propName.equals("boost")) { builder.boost(nodeFloatValue(propNode)); + deprecationLogger.deprecate( + "boost", + "Parameter [boost] on field [{}] is deprecated and will be removed in 8.0", + name); iterator.remove(); } else if (propName.equals("index_options")) { builder.indexOptions(nodeIndexOptionValue(propNode)); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java index 6b857da556a..69d120c9dab 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java @@ -48,6 +48,11 @@ public class BooleanFieldMapperTests extends MapperTestCase { b.field("type", "boolean"); } + @Override + protected void assertParseMaximalWarnings() { + assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0"); + } + public void testDefaults() throws IOException { MapperService mapperService = createMapperService(fieldMapping(this::minimalMapping)); @@ -170,6 +175,7 @@ public class BooleanFieldMapperTests extends MapperTestCase { MappedFieldType ft = mapperService.fieldType("field"); assertEquals(new BoostQuery(new TermQuery(new Term("field", "T")), 2.0f), ft.termQuery("true", null)); + assertParseMaximalWarnings(); } public void testFetchSourceValue() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index a3c09ec6e7f..a1dc35b7629 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -49,6 +49,11 @@ public class DateFieldMapperTests extends MapperTestCase { b.field("type", "date"); } + @Override + protected void assertParseMaximalWarnings() { + assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0"); + } + public void testDefaults() throws Exception { DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping)); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index 76a4375705c..688beff504f 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -131,6 +131,11 @@ public class KeywordFieldMapperTests extends MapperTestCase { b.field("type", "keyword"); } + @Override + protected void assertParseMaximalWarnings() { + assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0"); + } + public void testDefaults() throws Exception { XContentBuilder mapping = fieldMapping(this::minimalMapping); DocumentMapper mapper = createDocumentMapper(mapping); @@ -235,6 +240,7 @@ public class KeywordFieldMapperTests extends MapperTestCase { public void testBoost() throws IOException { MapperService mapperService = createMapperService(fieldMapping(b -> b.field("type", "keyword").field("boost", 2f))); assertThat(mapperService.fieldType("field").boost(), equalTo(2f)); + assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0"); } public void testEnableNorms() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java index 8732b42d663..4506ee06023 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -80,6 +80,11 @@ public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { b.field("type", "long_range"); } + @Override + protected void assertParseMaximalWarnings() { + assertWarnings("Parameter [boost] on field [field] is deprecated and will be removed in 8.0"); + } + private Object getFrom(String type) { if (type.equals("date_range")) { return FROM_DATE; diff --git a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java index 9d4624859de..b744e0205da 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -364,7 +364,7 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase { + 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(); + } + public static List fetchSourceValue(FieldMapper mapper, Object sourceValue) throws IOException { return fetchSourceValue(mapper, sourceValue, null); }