diff --git a/docs/reference/migration/migrate_8_0/mappings.asciidoc b/docs/reference/migration/migrate_8_0/mappings.asciidoc index b7d45f18e3035..8f90fff38a2fb 100644 --- a/docs/reference/migration/migrate_8_0/mappings.asciidoc +++ b/docs/reference/migration/migrate_8_0/mappings.asciidoc @@ -63,6 +63,21 @@ The `enabled` setting for `_field_names` should be removed from templates and ma Disabling _field_names is not necessary because it no longer carries a large index overhead. ==== +[[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. +==== + //tag::notable-breaking-changes[] .Java-time date formats replace joda-time formats [%collapsible] 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 53b612cd453e6..911c7caff2d96 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ParametrizedFieldMapper.java @@ -570,6 +570,12 @@ public final void parse(String name, ParserContext parserContext, Map builder, String name, Map b.field("field", "2016-03-11"))); 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 7711cc2125ecd..131e576e8f325 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 @@ protected void minimalMapping(XContentBuilder b) throws IOException { 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 void testIndexOptions() throws IOException { 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 8877e68192041..1d1105c83eb96 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -73,6 +73,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException { 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 248e9fb03ee5f..1a2e277a6d9c1 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -350,7 +350,7 @@ public void testExceptionUsingAnalyzerOnNumericField() { @Override protected void initializeAdditionalMappings(MapperService mapperService) throws IOException { mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping( - "string_boost", "type=text,boost=4", "string_no_pos", + "string_boost", "type=text", "string_no_pos", "type=text,index_options=docs")) ), MapperService.MergeReason.MAPPING_UPDATE); diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java index 734880c2ba045..b4d0cb70d4768 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java @@ -42,6 +42,7 @@ import java.util.function.BiFunction; import java.util.function.Supplier; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -82,13 +83,17 @@ public void testMinimalToMaximal() throws IOException { createMapperService(orig).documentMapper().mapping().toXContent(parsedFromOrig, INCLUDE_DEFAULTS); parsedFromOrig.endObject(); assertEquals(Strings.toString(orig), Strings.toString(parsedFromOrig)); - assertParseMinimalWarnings(); + assertParseMaximalWarnings(); } protected void assertParseMinimalWarnings() { // Most mappers don't emit any warnings } + protected void assertParseMaximalWarnings() { + // Most mappers don't emit any warnings + } + /** * Override to disable testing {@code meta} in fields that don't support it. */ @@ -132,6 +137,22 @@ public final void testMeta() throws IOException { ); } + 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(); + } + public static List fetchSourceValue(FieldMapper mapper, Object sourceValue) throws IOException { return fetchSourceValue(mapper, sourceValue, null); }