How does elasticsearch calculates clauses of a query?

Hello everyone,
Hope you are doing good.

How does elasticsearch clauses of a query? Which it eventually compares with max_clause_count and throws an RuntimeException if query exceeds maxClauseCount.

I understand how it calculates max_clause_count dynamically using heapInMb and threadPoolSize. But how does it calculates for a query that part is unclear?

I think the code reference - org.apache.lucene.search.MultiTermQuery.RewriteMethod#collectTerms