### 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
assertTrue(mergedMappings("*", new String[] { "empty" }, versionFC).isValid());
    }
    public void testMergeObjectIncompatibleTypes() throws Exception {
        var response = readFieldCapsResponse("fc-incompatible-object-compatible-subfields.json");
        IndexResolution resolution = IndexResolver.mergedMappings(
            SqlDataTypeRegistry.INSTANCE,
            "*",
            response,
            (fieldName, types) -> null,
            IndexResolver.PRESERVE_PROPERTIES
        );
        assertTrue(resolution.isValid());
        EsIndex esIndex = resolution.get();
        assertEquals(Set.of("index-1", "index-2"), esIndex.concreteIndices());
        EsField esField = esIndex.mapping().get("file");
        assertEquals(InvalidMappedField.class, esField.getClass());
        assertEquals(
            "mapped as [2] incompatible types: [keyword] in [index-2], [object] in [index-1]",
            ((InvalidMappedField) esField).errorMessage()
        );
        esField = esField.getProperties().get("name");
        assertNotNull(esField);
        assertEquals(esField.getDataType(), KEYWORD);
        assertEquals(KeywordEsField.class, esField.getClass());
    }
    private static FieldCapabilitiesResponse readFieldCapsResponse(String resourceName) throws IOException {
        InputStream stream = IndexResolverTests.class.getResourceAsStream("/" + resourceName);
        BytesReference ref = Streams.readFully(stream);
        XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, ref, XContentType.JSON);
        return FieldCapabilitiesResponse.fromXContent(parser);