Skip to content

Return HTTP 400 for too_many_clauses and too_many_nested_clauses errors#21725

Open
russcam wants to merge 2 commits into
opensearch-project:mainfrom
russcam:russcam/too-many-clauses-bad-request
Open

Return HTTP 400 for too_many_clauses and too_many_nested_clauses errors#21725
russcam wants to merge 2 commits into
opensearch-project:mainfrom
russcam:russcam/too-many-clauses-bad-request

Conversation

@russcam
Copy link
Copy Markdown
Contributor

@russcam russcam commented May 19, 2026

Description

Queries that exceed indices.query.bool.max_clause_count now respond with HTTP 400 instead of 500. Hitting this limit is a request-side problem (simplify the query or raise the operator-configured cap), so a client error is the correct response.

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Queries that exceed indices.query.bool.max_clause_count now respond
with HTTP 400 instead of 500. Hitting this limit is a request-side
problem (simplify the query or raise the operator-configured cap),
so a client error is the correct response.

Signed-off-by: Russ Cam <rcam@atlassian.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

PR Reviewer Guide 🔍

(Review updated until commit 550a289)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Incomplete Coverage

The switch case only handles IndexSearcher.TooManyClauses but not IndexSearcher.TooManyNestedClauses. The test file shows both exception types should return BAD_REQUEST (lines 117-118 in ExceptionsHelperTests.java), but only TooManyClauses is explicitly handled here. TooManyNestedClauses extends TooManyClauses, so it may work via inheritance, but explicit handling would be clearer and more maintainable if both are intended to be treated identically.

case IndexSearcher.TooManyClauses ignored -> RestStatus.BAD_REQUEST;

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

PR Code Suggestions ✨

Latest suggestions up to 550a289
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle TooManyNestedClauses exception

The switch case only handles TooManyClauses but not TooManyNestedClauses. According
to the test file, both exception types should return BAD_REQUEST. Add a case for
IndexSearcher.TooManyNestedClauses to ensure consistent error handling.

libs/core/src/main/java/org/opensearch/ExceptionsHelper.java [135]

 case IndexSearcher.TooManyClauses ignored -> RestStatus.BAD_REQUEST;
+case IndexSearcher.TooManyNestedClauses ignored -> RestStatus.BAD_REQUEST;
Suggestion importance[1-10]: 9

__

Why: The test file explicitly verifies that TooManyNestedClauses should return BAD_REQUEST (line 118), but the production code only handles TooManyClauses. This is a critical bug where the exception handling is incomplete, potentially causing TooManyNestedClauses to incorrectly return INTERNAL_SERVER_ERROR instead of BAD_REQUEST.

High

Previous suggestions

Suggestions up to commit 550a289
CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle TooManyNestedClauses exception

The switch case only handles IndexSearcher.TooManyClauses but the test file shows
that IndexSearcher.TooManyNestedClauses should also return BAD_REQUEST. Add a case
for TooManyNestedClauses to match the expected behavior verified in the test.

libs/core/src/main/java/org/opensearch/ExceptionsHelper.java [135]

 case IndexSearcher.TooManyClauses ignored -> RestStatus.BAD_REQUEST;
+case IndexSearcher.TooManyNestedClauses ignored -> RestStatus.BAD_REQUEST;
Suggestion importance[1-10]: 9

__

Why: The test at line 118 verifies that IndexSearcher.TooManyNestedClauses should return RestStatus.BAD_REQUEST, but the switch statement only handles TooManyClauses. This is a critical missing case that causes the test to fail or behave incorrectly.

High

@github-actions
Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 550a289

@github-actions
Copy link
Copy Markdown
Contributor

✅ Gradle check result for 550a289: SUCCESS

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.46%. Comparing base (bc96138) to head (550a289).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #21725      +/-   ##
============================================
- Coverage     73.52%   73.46%   -0.06%     
+ Complexity    74892    74814      -78     
============================================
  Files          5997     5997              
  Lines        339688   339689       +1     
  Branches      48961    48961              
============================================
- Hits         249746   249554     -192     
- Misses        70089    70220     +131     
- Partials      19853    19915      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

russcam added a commit to russcam/documentation-website that referenced this pull request May 19, 2026
…rors

Relates: opensearch-project/OpenSearch#21725

Queries that exceed indices.query.bool.max_clause_count now respond
with HTTP 400 instead of 500. Hitting this limit is a request-side
problem (simplify the query or raise the operator-configured cap),
so a client error is the correct response.

Signed-off-by: Russ Cam <rcam@atlassian.com>
@russcam
Copy link
Copy Markdown
Contributor Author

russcam commented May 19, 2026

Opened related documentation PR: opensearch-project/documentation-website#12446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant