### 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
throw new UnsupportedOperationException(
                "[wildcard] queries are not currently supported on keyed " + "[" + CONTENT_TYPE + "] fields."
            );
        }
        @Override
        public Query termQueryCaseInsensitive(Object value, SearchExecutionContext context) {
            return AutomatonQueries.caseInsensitiveTermQuery(new Term(name(), indexedValueForSearch(value)));
        }
        @Override
        public TermsEnum getTerms(boolean caseInsensitive, String string, SearchExecutionContext queryShardContext, String searchAfter)
            throws IOException {
            IndexReader reader = queryShardContext.searcher().getTopReaderContext().reader();
            Terms terms = MultiTerms.getTerms(reader, name());
            if (terms == null) {
                
                return null;
            }
            Automaton a = Automata.makeString(key + FlattenedFieldParser.SEPARATOR);
            if (caseInsensitive) {
                a = Operations.concatenate(a, AutomatonQueries.caseInsensitivePrefix(string));
            } else {
                a = Operations.concatenate(a, Automata.makeString(string));
                a = Operations.concatenate(a, Automata.makeAnyString());
            }
            a = MinimizationOperations.minimize(a, Integer.MAX_VALUE);
            CompiledAutomaton automaton = new CompiledAutomaton(a);
            if (searchAfter != null) {
                BytesRef searchAfterWithFieldName = new BytesRef(key + FlattenedFieldParser.SEPARATOR + searchAfter);
                TermsEnum seekedEnum = terms.intersect(automaton, searchAfterWithFieldName);
                return new TranslatingTermsEnum(seekedEnum);