diff --git a/docs/reference/migration/migrate_7_0/search.asciidoc b/docs/reference/migration/migrate_7_0/search.asciidoc index b7aa15861afad..6cf004da6ce8d 100644 --- a/docs/reference/migration/migrate_7_0/search.asciidoc +++ b/docs/reference/migration/migrate_7_0/search.asciidoc @@ -61,6 +61,7 @@ Scroll queries are not meant to be cached. [float] ==== Scroll queries cannot use `rescore` anymore + Including a rescore clause on a query that creates a scroll (`scroll=1m`) has been deprecated in 6.5 and will now return a `400 - Bad request`. Allowing rescore on scroll queries would break the scroll sort. In the 6.x line, the @@ -123,3 +124,9 @@ max number of concurrent shard requests per node. The default is now `5`. `max_score` used to be set to `0` whenever scores are not tracked. `null` is now used instead which is a more appropriate value for a scenario where scores are not available. + +[float] +==== Negative boosts are not allowed + +Setting a negative `boost` in a query, deprecated in 6x, are not allowed in this version. +To deboost a specific query you can use a `boost` comprise between 0 and 1. \ No newline at end of file diff --git a/server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java index 7e667af054452..c0fb00128e556 100644 --- a/server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java @@ -159,6 +159,10 @@ public final float boost() { @SuppressWarnings("unchecked") @Override public final QB boost(float boost) { + if (Float.compare(boost, 0f) < 0) { + throw new IllegalArgumentException("negative [boost] are not allowed in [" + toString() + "], " + + "use a value between 0 and 1 to deboost"); + } this.boost = boost; return (QB) this; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index 4d8ff046ca9ce..4c030ddb28518 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -101,6 +101,13 @@ public final QB createTestQueryBuilder() { */ protected abstract QB doCreateTestQueryBuilder(); + public void testNegativeBoosts() { + QB testQuery = createTestQueryBuilder(); + IllegalArgumentException exc = + expectThrows(IllegalArgumentException.class, () -> testQuery.boost(-0.5f)); + assertThat(exc.getMessage(), containsString("negative [boost]")); + } + /** * Generic test that creates new query from the test query and checks both for equality * and asserts equality on the two queries.