### CI Link

https://gradle-enterprise.elastic.co/s/b57j3vuz7qk2q/tests/:server:test/org.elasticsearch.index.query.SpanContainingQueryBuilderTests/testMaxNestedDepth

### Repro line

`gradlew ':server:test' --tests "org.elasticsearch.index.query.SpanContainingQueryBuilderTests.testMaxNestedDepth" -Dtests.seed=FCAC1620A8E66666 -Dtests.locale=de-AT -Dtests.timezone=America/Shiprock -Druntime.java=19`

### Does it reproduce?

Yes

### Applicable branches

main

### Failure history

https://gradle-enterprise.elastic.co/scans/tests?search.timeZoneId=Europe/Berlin&tests.container=org.elasticsearch.index.query.SpanContainingQueryBuilderTests&tests.test=testMaxNestedDepth#

### Failure excerpt

```
java.lang.OutOfMemoryError: Java heap space	
	at __randomizedtesting.SeedInfo.seed([FCAC1620A8E66666:445BD40EBC1BAFC9]:0)	
		•••
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:88)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:89)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanContainingQueryBuilder.doXContent(SpanContainingQueryBuilder.java:87)	
```
server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java
+ "]"
            );
        }
    }
    /**
     * Adds {@code boost} and {@code query_name} parsing to the
     * {@link AbstractObjectParser} passed in. All query builders except
     * {@link MatchAllQueryBuilder} and {@link MatchNoneQueryBuilder} support these fields so they
     * should use this method.
     */
    protected static void declareStandardFields(AbstractObjectParser<? extends QueryBuilder, ?> parser) {
        parser.declareFloat(QueryBuilder::boost, AbstractQueryBuilder.BOOST_FIELD);
        parser.declareString(QueryBuilder::queryName, AbstractQueryBuilder.NAME_FIELD);
    }
    /**
     * Set the maximum nested depth of bool queries.
     * Default value is 20.
     */
    public static void setMaxNestedDepth(int maxNestedDepth) {
        if (maxNestedDepth < 1) {
            throw new IllegalArgumentException("maxNestedDepth must be >= 1");
        }
        AbstractQueryBuilder.maxNestedDepth = maxNestedDepth;
    }
    @Override
    public final String toString() {
        return Strings.toString(this, true, true);
    }
}