Skip to content

Commit 2cd2ae0

Browse files
committed
Query rules: Check if MGET request failed when we retrieve query rules (elastic#123616)
1 parent c5b7ec4 commit 2cd2ae0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
setup:
2+
- do:
3+
bulk:
4+
refresh: true
5+
index: test-index1
6+
body:
7+
- index:
8+
_id: foo
9+
- { "text": "foo - pinned doc for foo" }
10+
11+
---
12+
"query rules retriever when the .query-rules system index is missing":
13+
- skip:
14+
features: [ headers ]
15+
- do:
16+
search:
17+
index: test-index1
18+
body:
19+
retriever:
20+
rule:
21+
match_criteria:
22+
foo: foo
23+
bar: bar
24+
ruleset_ids:
25+
abc
26+
retriever:
27+
standard:
28+
query:
29+
query_string:
30+
query: bar
31+
explain: true
32+
catch: "missing"

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/RuleQueryBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,15 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
252252

253253
for (MultiGetItemResponse item : multiGetResponse) {
254254
String rulesetId = item.getId();
255+
// this usually happens when the system index does not exist because no query rules were created yet
256+
if (item.isFailed()) {
257+
listener.onFailure(item.getFailure().getFailure());
258+
return;
259+
}
260+
255261
GetResponse getResponse = item.getResponse();
256262

263+
// this happens when an individual query ruleset cannot be found
257264
if (getResponse.isExists() == false) {
258265
listener.onFailure(new ResourceNotFoundException("query ruleset " + rulesetId + " not found"));
259266
return;

0 commit comments

Comments
 (0)