Understanding the Nested Clause Limit

When your search queries contain many fields or use complex parse modes, you may encounter a "too many nested clauses" error. This happens when a single query exceeds the 1,024 nested clause limit in SearchStax's underlying search engine.

What Is the Nested Clause Limit?

SearchStax Site Search supports up to 1,024 nested clauses per query. A "clause" is an individual search condition. When you search across multiple fields or use certain parsing modes, a single user search can generate hundreds or even thousands of clauses.

You'll know you've hit this limit when you see an error like this:

org.apache.lucene.search.IndexSearcher$TooManyNestedClauses:
Query contains too many nested clauses; maxClauseCount is set to 1024

This error typically appears when you're migrating existing search configurations to SearchStax and testing with multi-word search phrases.

What Creates Nested Clauses?

Several factors in your search configuration can multiply the number of clauses in a query:

Number of Searchable Fields

Searching across many fields increases clause count. While a dozen fields typically isn't an issue on its own, when combined with other multipliers, it can push you over the 1,024 clause limit.

Example: If you search 20 fields for a single term, that's 20 clauses. If you search those same 20 fields with a 5-word phrase, you could generate 100+ clauses depending on your parse mode.

Multi-Language Field Configurations

Searching all language variants of your fields multiplies clause count. If you're displaying results in English, you typically only need to search the English fields—not Spanish, French, and German fields too.

Example: 10 fields × 5 languages = 50 fields being searched when you might only need 10.

Fulltext Field Parse Modes

The biggest multiplier comes from how your search analyzes multi-word queries against fulltext fields. This is especially common in Drupal implementations using "Multiple Words" parse mode.

For fulltext fields: A 5-word search phrase like "this is a search term" generates 6 clauses per field:

  • Individual words: "this", "is", "a", "search", "term"
  • Complete phrase: "this is a search term"

If you're searching 20 fulltext fields, that's 120 clauses for a single user query.

Fulltext Ngram Fields

Fulltext ngram fields create even more clauses because they analyze partial word combinations.

For fulltext ngram fields: The same 5-word phrase generates 15 clauses per field:

  • Individual words: "this", "is", "a", "search", "term"
  • 2-word combinations: "this is", "is a", "a search", "search term"
  • 3-word combinations: "this is a", "is a search", "a search term"
  • Complete phrase: "this is a search term"

If you're searching 20 fulltext ngram fields, that's 300 clauses for a single user query.

Calculating Your Clause Count

You can estimate whether you'll hit the limit with this formula:

Total clauses = (number of fulltext fields × 6 × word count) +
                (number of ngram fields × 15 × word count) +
                (number of exact match fields × 1)

Example scenario:

  • 15 fulltext fields
  • 10 fulltext ngram fields
  • 5 exact match fields
  • User searches "hospital patient management system" (4 words)
Calculation:
(15 fields × 6 clauses × 4 words) = 360 clauses
(10 fields × 15 clauses × 4 words) = 600 clauses
(5 fields × 1 clause) = 5 clauses
Total = 965 clauses

This configuration is already close to the 1,024 limit with a 4-word search. A 5-word search would exceed it.

Next Steps

If your search configuration is approaching or exceeding the nested clause limit, you have several options to reduce clause count. The most effective solution is using copy fields to consolidate multiple searchable fields into a single field.

Related articles:

Articles in this section