### 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
/**
     * Replace the generic test from superclass, wrapper query only expects
     * to find `query` field with nested query and should throw exception for
     * anything else.
     */
    @Override
    public void testUnknownField() {
        String json = "{ \"" + WrapperQueryBuilder.NAME + "\" : {\"bogusField\" : \"someValue\"} }";
        ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
        assertTrue(e.getMessage().contains("bogusField"));
    }
    public void testFromJson() throws IOException {
        String json = """
            {
              "wrapper" : {
                "query" : "e30="
              }
            }""";
        WrapperQueryBuilder parsed = (WrapperQueryBuilder) parseQuery(json);
        checkGeneratedJson(json, parsed);
        assertEquals(json, "{}", new String(parsed.source(), StandardCharsets.UTF_8));
    }
    @Override
    public void testMustRewrite() throws IOException {
        TermQueryBuilder tqb = new TermQueryBuilder(TEXT_FIELD_NAME, "bar");
        WrapperQueryBuilder qb = new WrapperQueryBuilder(tqb.toString());
        UnsupportedOperationException e = expectThrows(
            UnsupportedOperationException.class,
            () -> qb.toQuery(createSearchExecutionContext())
        );