Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow negative query boost #34486

Merged
merged 1 commit into from Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/migration/migrate_7_0/search.asciidoc
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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.
Expand Down