### Elasticsearch Version

8.6 and above

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Unix

### Problem Description

While trying to run a script query on an index with a percolator type field but running into error 
```
        "type": "document_parsing_exception",
        "reason": "[10:39] failed to parse: [10:39] [bool] failed to parse field [filter]"
```
This worked in 7.17.0 but does not work in 8.6 (also on current main )

### Steps to Reproduce


1. Create index with percolator field
```
PUT /debug-index-01
{
    "mappings": {
        "properties": {
            "query": {
                "type": "percolator"
            }
        }
    }
}
```
2. Run POST with script on index
```
POST /debug-index-01/_doc
{
    "query": {
        "bool": {
            "filter": [
                {
                    "script": {
                        "script": {
                            "source": "return params.x ? true : false",
                            "lang": "painless",
                            "params": {
                                "x": true
                            }
                        }
                    }
                }
            ]
        }
    }
}
```

On 7.17 it says creates the document.
On 8.8.2 it gives the response below:
```
{
  "error": {
    "root_cause": [
      {
        "type": "document_parsing_exception",
        "reason": "[10:39] failed to parse: [10:39] [bool] failed to parse field [filter]"
      }
    ],
    "type": "document_parsing_exception",
    "reason": "[10:39] failed to parse: [10:39] [bool] failed to parse field [filter]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": "[10:39] [bool] failed to parse field [filter]",
      "caused_by": {
        "type": "x_content_parse_exception",
        "reason": "[10:39] [script] failed to parse field [params]",
        "caused_by": {
          "type": "unsupported_operation_exception",
          "reason": null
        }
      }
    }
  },
  "status": 400
}
```

### Logs (if relevant)

_No response_
server/src/main/java/org/elasticsearch/index/mapper/DotExpandingXContentParser.java
if (resultSize == 1 && field.endsWith(".") == false) {
                    return;
                }
                subpaths = extractAndValidateResults(field, list, resultSize);
            }
            pushSubParser(delegate, subpaths);
        }
        private void pushSubParser(XContentParser delegate, String[] subpaths) throws IOException {
            XContentLocation location = delegate.getTokenLocation();
            Token token = delegate.nextToken();
            final XContentParser subParser;
            if (token == Token.START_OBJECT || token == Token.START_ARRAY) {
                subParser = new XContentSubParser(delegate);
            } else {
                if (token == Token.END_OBJECT || token == Token.END_ARRAY) {
                    throwExpectedOpen(token);
                }
                subParser = new SingletonValueXContentParser(delegate);
            }
            parsers.push(new DotExpandingXContentParser(subParser, subpaths, location, contentPath));
        }
        private static void throwExpectedOpen(Token token) {
            throw new IllegalStateException("Expecting START_OBJECT or START_ARRAY or VALUE but got [" + token + "]");
        }
        private static String[] extractAndValidateResults(String field, String[] list, int resultSize) {
            final String[] subpaths = new String[resultSize];
            for (int i = 0; i < resultSize; i++) {
                String part = list[i];