### 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)
```
server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java
if (parser.nextToken() != XContentParser.Token.END_OBJECT) {
            throw new ParsingException(
                parser.getTokenLocation(),
                "[" + queryName + "] malformed query, expected [END_OBJECT] but found [" + parser.currentToken() + "]"
            );
        }
        return result;
    }
    
    protected static <T> T requireValue(T value, String message) {
        if (value == null) {
            throw new IllegalArgumentException(message);
        }
        return value;
    }
    protected static void throwParsingExceptionOnMultipleFields(
        String queryName,
        XContentLocation contentLocation,
        String processedFieldName,
        String currentFieldName
    ) {
        if (processedFieldName != null) {
            throw new ParsingException(
                contentLocation,
                "["
                    + queryName
                    + "] query doesn't support multiple fields, found ["
                    + processedFieldName
                    + "] and ["
                    + currentFieldName