From db1c76bef514fa36935e14f51a9430a528f8c94e Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 May 2024 15:30:02 -0700 Subject: [PATCH] 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 --- docs/changelog/109048.yaml | 6 ++++++ .../painless/action/PainlessExecuteAction.java | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 docs/changelog/109048.yaml diff --git a/docs/changelog/109048.yaml b/docs/changelog/109048.yaml new file mode 100644 index 000000000000..8bae082404ec --- /dev/null +++ b/docs/changelog/109048.yaml @@ -0,0 +1,6 @@ +pr: 109048 +summary: Guard against a null scorer in painless execute +area: Infra/Scripting +type: bug +issues: + - 43541 diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java index 6ab5fc724c71..0736fd4ef4a8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java @@ -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();