mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
Guard against a null scorer in painless execute (#109048)
The painless execute api allows for a sample document and query to be provided. If the query does not actually match the document, a null scorer is produced. This commit guards against that condition, returning a clearer error message indicating what happened. closes #43541
This commit is contained in:
parent
b8894c39ed
commit
db1c76bef5
2 changed files with 9 additions and 0 deletions
6
docs/changelog/109048.yaml
Normal file
6
docs/changelog/109048.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
pr: 109048
|
||||
summary: Guard against a null scorer in painless execute
|
||||
area: Infra/Scripting
|
||||
type: bug
|
||||
issues:
|
||||
- 43541
|
|
@ -648,6 +648,9 @@ public class PainlessExecuteAction {
|
|||
luceneQuery = indexSearcher.rewrite(luceneQuery);
|
||||
Weight weight = indexSearcher.createWeight(luceneQuery, ScoreMode.COMPLETE, 1f);
|
||||
Scorer scorer = weight.scorer(indexSearcher.getIndexReader().leaves().get(0));
|
||||
if (scorer == null) {
|
||||
throw new IllegalArgumentException("The provided query did not match the sample document");
|
||||
}
|
||||
// Consume the first (and only) match.
|
||||
int docID = scorer.iterator().nextDoc();
|
||||
assert docID == scorer.docID();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue