Skip to content

Commit 47e352f

Browse files
authored
Throw nicer exception in SpanBooleanQueryRewriteWithMaxClause (#126387)
Throw an ElasticsearchStatusException with a RestStatus.BAD_REQUEST code instead of a generic RuntimeException.
1 parent 997a7b8 commit 47e352f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

server/src/main/java/org/elasticsearch/common/lucene/search/SpanBooleanQueryRewriteWithMaxClause.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import org.apache.lucene.search.Query;
2525
import org.apache.lucene.util.AttributeSource;
2626
import org.apache.lucene.util.BytesRef;
27+
import org.elasticsearch.ElasticsearchStatusException;
2728
import org.elasticsearch.lucene.queries.SpanMatchNoDocsQuery;
29+
import org.elasticsearch.rest.RestStatus;
2830

2931
import java.io.IOException;
3032
import java.util.Collection;
@@ -95,13 +97,14 @@ private Collection<SpanQuery> collectTerms(IndexReader reader, MultiTermQuery qu
9597
while ((bytes = termsEnum.next()) != null) {
9698
if (queries.size() >= maxExpansions) {
9799
if (hardLimit) {
98-
throw new RuntimeException(
100+
throw new ElasticsearchStatusException(
99101
"["
100102
+ query.toString()
101103
+ " ] "
102104
+ "exceeds maxClauseCount [ Boolean maxClauseCount is set to "
103105
+ IndexSearcher.getMaxClauseCount()
104-
+ "]"
106+
+ "]",
107+
RestStatus.BAD_REQUEST
105108
);
106109
} else {
107110
return queries;

0 commit comments

Comments
 (0)