### Description

For certain mappings the following query:
```
POST _query?error_trace
{
  “query”: “”"
  from * [metadata _index] | limit 10000
  “”"
}
```

triggers a CCE:
```
{ "error": {
    "root_cause": [
      {
        "type": "class_cast_exception",
        "reason": "class org.elasticsearch.xpack.ql.type.UnsupportedEsField cannot be cast to class org.elasticsearch.xpack.ql.type.InvalidMappedField (org.elasticsearch.xpack.ql.type.UnsupportedEsField and org.elasticsearch.xpack.ql.type.InvalidMappedField are in unnamed module of loader java.net.FactoryURLClassLoader @6eb5b9e7)",
        "stack_trace": """org.elasticsearch.ElasticsearchException$1: class org.elasticsearch.xpack.ql.type.UnsupportedEsField cannot be cast to class org.elasticsearch.xpack.ql.type.InvalidMappedField (org.elasticsearch.xpack.ql.type.UnsupportedEsField and org.elasticsearch.xpack.ql.type.InvalidMappedField are in unnamed module of loader java.net.FactoryURLClassLoader @6eb5b9e7)

Caused by: java.lang.ClassCastException: class org.elasticsearch.xpack.ql.type.UnsupportedEsField cannot be cast to class 
org.elasticsearch.xpack.ql.type.InvalidMappedField (org.elasticsearch.xpack.ql.type.UnsupportedEsField and org.elasticsearch.xpack.ql.type.InvalidMappedField are in unnamed module of loader java.net.FactoryURLClassLoader @6eb5b9e7)
	at org.elasticsearch.xpack.ql.index.IndexResolver.buildIndices(IndexResolver.java:771)
	at org.elasticsearch.xpack.ql.index.IndexResolver.mergedMappings(IndexResolver.java:466)
	at org.elasticsearch.xpack.ql.index.IndexResolver.lambda$resolveAsMergedMapping$8(IndexResolver.java:381)
	at org.elasticsearch.server@8.11.0/org.elasticsearch.action.ActionListenerImplementations$ResponseWrappingActionListener.onResponse(ActionListenerImplementations.java:236)
	... 21 more
```
x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java
private static EsField createField(
        DataTypeRegistry typeRegistry,
        String fieldName,
        Map<String, Map<String, FieldCapabilities>> globalCaps,
        Map<String, EsField> hierarchicalMapping,
        Map<String, EsField> flattedMapping,
        Function<String, EsField> field
    ) {
        Map<String, EsField> parentProps = hierarchicalMapping;
        int dot = fieldName.lastIndexOf('.');
        String fullFieldName = fieldName;
        EsField parent = null;
        if (dot >= 0) {
            String parentName = fieldName.substring(0, dot);
            fieldName = fieldName.substring(dot + 1);
            parent = flattedMapping.get(parentName);
            if (parent == null) {
                Map<String, FieldCapabilities> map = globalCaps.get(parentName);
                Function<String, EsField> fieldFunction;
                
                if (map == null) {
                    
                    fieldFunction = s -> createField(typeRegistry, s, OBJECT.esType(), null, new TreeMap<>(), false, true);
                } else {
                    Iterator<FieldCapabilities> iterator = map.values().iterator();
                    FieldCapabilities parentCap = iterator.next();
                    if (iterator.hasNext() && UNMAPPED.equals(parentCap.getType())) {
                        parentCap = iterator.next();
                    }
                    final FieldCapabilities parentC = parentCap;