# How does elasticsearch calculates clauses of a query?

**URL:** <https://discuss.elastic.co/t/how-does-elasticsearch-calculates-clauses-of-a-query/358895>\
**Category:** Elasticsearch\
**Created:** [May 7, 2024, 6:31am UTC](https://discuss.elastic.co/t/how-does-elasticsearch-calculates-clauses-of-a-query/358895 "2024-05-07T06:31:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya\_Teltia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_teltia/32/122447_2.png) [@Aditya\_Teltia](https://discuss.elastic.co/u/Aditya_Teltia)\
**Post date:** [May 7, 2024, 6:31am UTC](https://discuss.elastic.co/t/how-does-elasticsearch-calculates-clauses-of-a-query/358895/1 "2024-05-07T06:31:40Z")

</div>

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`
