### Elasticsearch Version

8.8.0-SNAPSHOT

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

MacOS

### Problem Description

API when called is returning invalid response, on the same data terms aggs query runs fine 

![image](https://user-images.githubusercontent.com/3505601/220749805-ddf0d735-60d5-4e45-85bf-941ea3076a3f.png)


When run as aggs query 

![image](https://user-images.githubusercontent.com/3505601/220764360-49f7b648-8b15-43cf-afe2-01bd62e8ebc5.png)


### Steps to Reproduce

Queries are mentioned above ^^

### Logs (if relevant)

_No response_
server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java
splitQueriesOnWhitespace,
                meta };
        }
        @Override
        public FlattenedFieldMapper build(MapperBuilderContext context) {
            MultiFields multiFields = multiFieldsBuilder.build(this, context);
            if (multiFields.iterator().hasNext()) {
                throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name + "] does not support [fields]");
            }
            CopyTo copyTo = this.copyTo.build();
            if (copyTo.copyToFields().isEmpty() == false) {
                throw new IllegalArgumentException(CONTENT_TYPE + " field [" + name + "] does not support [copy_to]");
            }
            MappedFieldType ft = new RootFlattenedFieldType(
                context.buildFullName(name),
                indexed.get(),
                hasDocValues.get(),
                meta.get(),
                splitQueriesOnWhitespace.get(),
                eagerGlobalOrdinals.get()
            );
            return new FlattenedFieldMapper(name, ft, this);
        }
    }
    public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));
    /**
     * A field type that represents the values under a particular JSON key, used
     * when searching under a specific key as in 'my_flattened.key: some_value'.
     */
    public static final class KeyedFlattenedFieldType extends StringFieldType {