### CI Link

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

### Repro line

`gradlew ':server:test' --tests "org.elasticsearch.index.query.SpanNotQueryBuilderTests.testMaxNestedDepth" -Dtests.seed=FCAC1620A8E66666 -Dtests.locale=hu -Dtests.timezone=Etc/GMT+11 -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.SpanNotQueryBuilderTests&tests.test=testMaxNestedDepth#

### Failure excerpt

```
java.lang.OutOfMemoryError: Java heap space	
	at __randomizedtesting.SeedInfo.seed([FCAC1620A8E66666:445BD40EBC1BAFC9]:0)	
		•••
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:145)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:148)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:148)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:148)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:146)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:148)	
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:80)	
	at org.elasticsearch.index.query.SpanNotQueryBuilder.doXContent(SpanNotQueryBuilder.java:148)
```
test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java
}
                    if (objectIndex < mutation) {
                        
                        break;
                    } else {
                        
                        mutation++;
                    }
                }
                results.add(new Tuple<>(out.bytes().utf8ToString(), exception));
            }
        }
        return results;
    }
    /**
     * Returns a map where the keys are object names that won't trigger a standard exception (an exception that contains the string
     * "unknown field [newField]") through {@link #testUnknownObjectException()}. The value is a string that is contained in the thrown
     * exception or null in the case that no exception is thrown (including their children).
     * Default is an empty Map. Can be overridden by subclasses that test queries which contain objects that get parsed on the data nodes
     * (e.g. score functions) or objects that can contain arbitrary content (e.g. documents for percolate or more like this query, params
     * for scripts) and/or expect some content(e.g documents with geojson geometries).
     */
    protected Map<String, String> getObjectsHoldingArbitraryContent() {
        return Collections.emptyMap();
    }
    /**
     * Test that wraps the randomly generated query into an array as follows: { "query_name" : [{}]}
     * This causes unexpected situations in parser code that may not be handled properly.
     */
    public final void testQueryWrappedInArray() {