### 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/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/index/IndexResolverTests.java
addFieldCaps(fieldCaps, "some_field", esFieldType, false, false);
        addFieldCaps(fieldCaps, "another_field", "object", true, false);
        addFieldCaps(fieldCaps, "another_field._foo", esFieldType, true, false);
        addFieldCaps(fieldCaps, "nested_field", "object", false, false);
        addFieldCaps(fieldCaps, "nested_field.sub_field1", esFieldType, true, true);
        addFieldCaps(fieldCaps, "nested_field.sub_field1.bar", esFieldType, true, true);
        addFieldCaps(fieldCaps, "nested_field.sub_field2", esFieldType, true, true);
        
        addFieldCaps(fieldCaps, "nested_field.sub_field2.bar", "keyword", true, true);
        addFieldCaps(fieldCaps, "text", "keyword", true, true);
        String wildcard = "*";
        IndexResolution resolution = mergedMappings(wildcard, new String[] { "index" }, fieldCaps);
        assertTrue(resolution.isValid());
        EsIndex esIndex = resolution.get();
        assertEquals(wildcard, esIndex.name());
        assertEquals(Set.of("index"), resolution.get().concreteIndices());
        assertEquals(UNSUPPORTED, esIndex.mapping().get("some_field").getDataType());
        assertEquals(OBJECT, esIndex.mapping().get("nested_field").getDataType());
        assertEquals(UNSUPPORTED, esIndex.mapping().get("nested_field").getProperties().get("sub_field1").getDataType());
        assertEquals(
            UNSUPPORTED,
            esIndex.mapping().get("nested_field").getProperties().get("sub_field1").getProperties().get("bar").getDataType()
        );
        assertEquals(UNSUPPORTED, esIndex.mapping().get("nested_field").getProperties().get("sub_field2").getDataType());
        assertEquals(
            UNSUPPORTED,
            esIndex.mapping().get("nested_field").getProperties().get("sub_field2").getProperties().get("bar").getDataType()
        );
        assertEquals(KEYWORD, esIndex.mapping().get("text").getDataType());
        assertEquals(OBJECT, esIndex.mapping().get("another_field").getDataType());