### CI Link

https://gradle-enterprise.elastic.co/s/sdobpnvk6mf6w

### Repro line

gradlew ':server:test' --tests "org.elasticsearch.index.query.WrapperQueryBuilderTests.testMaxNestedDepth" -Dtests.seed=68EFB0E52A29A3C7 -Dtests.locale=ar-TN -Dtests.timezone=America/Guadeloupe -Druntime.java=19

### Does it reproduce?

Yes

### Applicable branches

main

### Failure history

_No response_

### Failure excerpt

```
 2> REPRODUCE WITH: ./gradlew ':server:test' --tests "org.elasticsearch.index.query.WrapperQueryBuilderTests.testMaxNestedDepth" -Dtests.seed=68EFB0E52A29A3C7 -Dtests.locale=ar-TN -Dtests.timezone=America/Guadeloupe -Druntime.java=19
  2> java.lang.OutOfMemoryError: Java heap space
        at __randomizedtesting.SeedInfo.seed([68EFB0E52A29A3C7:D01872CB3ED46A68]:0)
        at java.base/java.util.Arrays.copyOf(Arrays.java:3537)
        at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:100)
        at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:132)
        at com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:2171)
        at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:244)
        at org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:187)
        at org.elasticsearch.xcontent.XContentBuilder.field(XContentBuilder.java:363)
        at org.elasticsearch.xcontent.XContentBuilder.startObject(XContentBuilder.java:333)
        at org.elasticsearch.index.query.MatchAllQueryBuilder.doXContent(MatchAllQueryBuilder.java:45)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:236)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:235)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:236)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:235)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:235)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:235)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:236)
        at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:81)
        at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:258)
        ```
server/src/test/java/org/elasticsearch/index/query/WrapperQueryBuilderTests.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.index.query;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.memory.MemoryIndex;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.xcontent.XContentParseException;
import org.elasticsearch.xcontent.XContentType;
import org.hamcrest.Matchers;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import static org.elasticsearch.search.SearchModule.INDICES_MAX_NESTED_DEPTH_SETTING;
public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQueryBuilder> {