script_score query errors on negative scores (#53133)
7.5 and 7.6 had a regression that allowed for script_score queries to have negative scores. We have corrected this regression in #52478. This is an addition to #52478 that adds a test and release notes.
This commit is contained in:
parent
8851fb2a08
commit
7e2a9f58ee
|
@ -11,3 +11,8 @@ Mapping::
|
||||||
* Dynamic mappings in indices created on 8.0 and later have stricter validation at mapping update time and
|
* Dynamic mappings in indices created on 8.0 and later have stricter validation at mapping update time and
|
||||||
results in a deprecation warning for indices created in Elasticsearch 7.7.0 and later.
|
results in a deprecation warning for indices created in Elasticsearch 7.7.0 and later.
|
||||||
(e.g. incorrect analyzer settings or unknown field types). {pull}51233[#51233]
|
(e.g. incorrect analyzer settings or unknown field types). {pull}51233[#51233]
|
||||||
|
|
||||||
|
Search::
|
||||||
|
* A regression that allowed negative scores in a script_score query was corrected.
|
||||||
|
A behaviour is restored that throws an error if script_score query produces
|
||||||
|
a negative score {pull}52478[#52478].
|
||||||
|
|
|
@ -131,6 +131,14 @@ public class ScriptScoreQueryTests extends ESTestCase {
|
||||||
assertThat(explanation.getValue(), equalTo(2.0f));
|
assertThat(explanation.getValue(), equalTo(2.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScriptScoreErrorOnNegativeScore() {
|
||||||
|
Script script = new Script("script that returns a negative score");
|
||||||
|
ScoreScript.LeafFactory factory = newFactory(script, false, explanation -> -1000.0);
|
||||||
|
ScriptScoreQuery query = new ScriptScoreQuery(Queries.newMatchAllQuery(), script, factory, null, "index", 0, Version.CURRENT);
|
||||||
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> searcher.search(query, 1));
|
||||||
|
assertTrue(e.getMessage().contains("Must be a non-negative score!"));
|
||||||
|
}
|
||||||
|
|
||||||
private ScoreScript.LeafFactory newFactory(Script script, boolean needsScore,
|
private ScoreScript.LeafFactory newFactory(Script script, boolean needsScore,
|
||||||
Function<ScoreScript.ExplanationHolder, Double> function) {
|
Function<ScoreScript.ExplanationHolder, Double> function) {
|
||||||
SearchLookup lookup = mock(SearchLookup.class);
|
SearchLookup lookup = mock(SearchLookup.class);
|
||||||
|
@ -153,4 +161,5 @@ public class ScriptScoreQueryTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue