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

Forbid negative scores in function_score query #35709

Prev Previous commit
Next Next commit
Address Jim's comments
  • Loading branch information
mayya-sharipova committed Nov 20, 2018
commit a9544c1e3e6958ba71638cb555b3b964d8f488f6
10 changes: 9 additions & 1 deletion docs/reference/migration/migrate_7_0/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ instead which is a more appropriate value for a scenario where scores are not av
==== 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.
To deboost a specific query you can use a `boost` comprise between 0 and 1.

[float]
==== Negative scores are not allowed in Function Score Query

Negative scores in the Function Score Query are deprecated in 6.x, and are
not allowed in this version. If a negative score is produced as a result
of computation (e.g. in `script_score` or `field_value_factor` functions),
an error will be thrown.
Original file line number Diff line number Diff line change
Expand Up @@ -448,35 +448,35 @@

"Exception on negative score":
- skip:
version: " - 6.99.99"
reason: "check on negative scores was added from 7.0.0 on"

- do:
index:
index: test
type: test
id: 1
body: { "test": "value beck", "num1": 1.0 }
- do:
indices.refresh: {}

- do:
catch: bad_request
search:
index: test
body:
query:
function_score:
query:
term:
test: value
"functions": [{
"script_score": {
"script": {
"lang": "painless",
"source": "doc['num1'].value - 10.0"
}
}
}]
version: " - 6.99.99"
reason: "check on negative scores was added from 7.0.0 on"

- do:
index:
index: test
type: test
id: 1
body: { "test": "value beck", "num1": 1.0 }
- do:
indices.refresh: {}

- do:
catch: bad_request
search:
index: test
body:
query:
function_score:
query:
term:
test: value
"functions": [{
"script_score": {
"script": {
"lang": "painless",
"source": "doc['num1'].value - 10.0"
}
}
}]
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.root_cause.0.reason: "script score function must not produce negative scores, but got: [-9.0]"}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public float score() throws IOException {
}
double factor = computeScore(docId, subQueryScore);
float finalScore = scoreCombiner.combine(subQueryScore, factor, maxBoost);
if (finalScore == Float.NEGATIVE_INFINITY || Float.isNaN(finalScore)) {
if (finalScore < 0 || Float.isNaN(finalScore)) {
/*
These scores are invalid for score based {@link org.apache.lucene.search.TopDocsCollector}s.
See {@link org.apache.lucene.search.TopScoreDocCollector} for details.
Expand Down