The code to compute the maximum number of clauses looks like this:

```java
    public static int calculateMaxClauseValue(ThreadPool threadPool) {
        int searchThreadPoolSize = threadPool.info(ThreadPool.Names.SEARCH).getMax();
        long heapSize = JvmStats.jvmStats().getMem().getHeapMax().getGb();
        return calculateMaxClauseValue(searchThreadPoolSize, heapSize);
    }

    static int calculateMaxClauseValue(long threadPoolSize, double heapInGb) {
        if (threadPoolSize <= 0 || heapInGb <= 0) {
            return DEFAULT_MAX_CLAUSE_COUNT;
        }
        // In a worst-case scenario, each clause may end up using up to 16k of memory
        // to load postings, positions, offsets, impacts, etc. So we calculate the
        // maximum number of clauses we can support in a single thread pool by
        // dividing the heap by 16k (or the equivalent, multiplying the heap in GB by
        // 64k), and then divide that by the number of possible concurrent search
        // threads.
        int maxClauseCount = (int) (heapInGb * 65_536 / threadPoolSize);
        return Math.max(DEFAULT_MAX_CLAUSE_COUNT, maxClauseCount);
    }
```

@nkhristinin reported the following surprising behavior. Say you have 1 vCPU and 2 search threads,
 - If you have 1GB of heap to the JVM then `maxClauseCount` will be 32,768.
 - But if you give slightly less than 1GB to the heap, e.g. 1023MB, then `long heapSize` will be 0 because of the cast performed by the `getGB()` call, and `maxClauseCount` will be set to 1,024 because ef the `heapInGb <= 0` condition.

It might not be a bad thing to be more careful with small heaps, but the code doesn't suggest that this behavior is intentional.
server/src/test/java/org/elasticsearch/search/SearchUtilsTests.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.search;
import org.elasticsearch.test.ESTestCase;
public class SearchUtilsTests extends ESTestCase {
    public void testConfigureMaxClauses() {
        
        assertEquals(8192, SearchUtils.calculateMaxClauseValue(4, 0.5));
        
        assertEquals(1024, SearchUtils.calculateMaxClauseValue(-1, 1));
        
        assertEquals(1024, SearchUtils.calculateMaxClauseValue(1024, 1));
        
        assertEquals(5041, SearchUtils.calculateMaxClauseValue(13, 1));
        
        assertEquals(26932, SearchUtils.calculateMaxClauseValue(73, 30));
    }
}