Skip to content

Commit e94dad6

Browse files
authored
Guard against a null scorer in painless execute (#109048) (#109192)
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
1 parent 652066d commit e94dad6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

docs/changelog/109048.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 109048
2+
summary: Guard against a null scorer in painless execute
3+
area: Infra/Scripting
4+
type: bug
5+
issues:
6+
- 43541

modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ static Response innerShardOperation(Request request, ScriptService scriptService
648648
luceneQuery = indexSearcher.rewrite(luceneQuery);
649649
Weight weight = indexSearcher.createWeight(luceneQuery, ScoreMode.COMPLETE, 1f);
650650
Scorer scorer = weight.scorer(indexSearcher.getIndexReader().leaves().get(0));
651+
if (scorer == null) {
652+
throw new IllegalArgumentException("The provided query did not match the sample document");
653+
}
651654
// Consume the first (and only) match.
652655
int docID = scorer.iterator().nextDoc();
653656
assert docID == scorer.docID();

0 commit comments

Comments
 (0)