Skip to content

Commit eb04b9d

Browse files
authored
Correct exception for missing nested path (#132408)
closes: #132407
1 parent 1c4b905 commit eb04b9d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

docs/changelog/132408.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132408
2+
summary: Correct exception for missing nested path
3+
area: Search
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/index/query/NestedQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public static <E extends Exception> Query toQuery(
300300
if (ignoreUnmapped) {
301301
return new MatchNoDocsQuery();
302302
} else {
303-
throw new IllegalStateException("[" + NAME + "] failed to find nested object under path [" + path + "]");
303+
throw new QueryShardException(context, "[" + NAME + "] failed to find nested object under path [" + path + "]");
304304
}
305305
}
306306
final BitSetProducer parentFilter;

server/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ public void testIgnoreUnmapped() throws IOException {
294294

295295
final NestedQueryBuilder failingQueryBuilder = new NestedQueryBuilder("unmapped", new MatchAllQueryBuilder(), ScoreMode.None);
296296
failingQueryBuilder.ignoreUnmapped(false);
297-
IllegalStateException e = expectThrows(
298-
IllegalStateException.class,
299-
() -> failingQueryBuilder.toQuery(createSearchExecutionContext())
300-
);
297+
QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createSearchExecutionContext()));
301298
assertThat(e.getMessage(), containsString("[" + NestedQueryBuilder.NAME + "] failed to find nested object under path [unmapped]"));
302299
}
303300

0 commit comments

Comments
 (0)