Skip to content

Throw TooManyClauses on intervals over-expansion - #16899

Open
mayya-sharipova wants to merge 1 commit into
apache:mainfrom
mayya-sharipova:intervals-expansion-exception
Open

mayya-sharipova wants to merge 1 commit into
apache:mainfrom
mayya-sharipova:intervals-expansion-exception

Conversation

@mayya-sharipova

@mayya-sharipova mayya-sharipova commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Throw TooManyClauses on intervals over-expansion

Multi-term intervals sources (prefix, wildcard, regexp, fuzzy, range
and multiterm) threw IllegalStateException when they expanded to more
than maxExpansions terms. Lucene's exception types are:

  • IllegalArgumentException: invalid arguments at query build time
  • IllegalStateException: invalid internal state
  • TooManyClauses: a query that expands to too many terms

Exceeding maxExpansions is not an invalid internal state. The query
matched more terms than its limit allows, which is the caller's error.
Throwing TooManyClauses lets applications built on Lucene recognise this
user error by type and report it as such, rather than matching on the
message of a generic IllegalStateException. maxExpansions is already
capped at IndexSearcher#getMaxClauseCount.

The matches() path now reports the pattern instead of the last matched
term, so both paths produce the same message.

Multi-term intervals sources (prefix, wildcard, regexp, fuzzy, range
and multiterm) threw IllegalStateException when they expanded to more
than maxExpansions terms. Lucene's exception types are:
- IllegalArgumentException: invalid arguments at query build time
- IllegalStateException: invalid internal state
- TooManyClauses: a query that expands to too many terms

Exceeding maxExpansions is not an invalid internal state. The query
matched more terms than its limit allows, which is the caller's error.
Throwing TooManyClauses lets applications built on Lucene recognise this
user error by type and report it as such, rather than matching on the
message of a generic IllegalStateException. maxExpansions is already
capped at IndexSearcher#getMaxClauseCount.

The matches() path now reports the pattern instead of the last matched
term, so both paths produce the same message.
uchiha-asha added a commit to uchiha-asha/elasticsearch that referenced this pull request Oct 23, 2026
Name the field and suggest a more selective pattern in the 400
message, add a TODO pointing to apache/lucene#16899, and lower the
max clause count in IntervalQueriesIT so the test indexes only a
few terms and asserts the exact limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant