### Elasticsearch Version

8.1.1

### Installed Plugins

_No response_

### Java Version

_bundled_

###  OS Version

Darwin Kernel Version 21.4.0

### Problem Description

Under certain conditions, executing a range enrich policy on a field with wrong datatype gives a NPE instead of a more comprehensible error.

### Steps to Reproduce

```
PUT enrich_index
{
  "mappings": {
    "properties": {
      "object": {
        "properties": {
          "field": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

PUT /_enrich/policy/enrich_policy
{
  "range": {
    "indices": "enrich_index",
    "match_field": "object",
    "enrich_fields": ["enrich_field"]
  }
}

POST /_enrich/policy/enrich_policy/_execute
```

Executing the policy returns:
```json
{
  "error" : {
    "root_cause" : [
      {
        "type" : "null_pointer_exception",
        "reason" : "Cannot invoke \"String.hashCode()\" because \"<local7>\" is null"
      }
    ],
    "type" : "null_pointer_exception",
    "reason" : "Cannot invoke \"String.hashCode()\" because \"<local7>\" is null"
  },
  "status" : 500
}
```

Interestingly enough, if the enrich index were created like this (without subfield in `object`):
```
PUT enrich_index
{
  "mappings": {
    "properties": {
      "object": {
        "properties": {
        }
      }
    }
  }
}
```
 

Executing the policy would return a much better error:
```json
{
  "error" : {
    "root_cause" : [
      {
        "type" : "exception",
        "reason" : "Field 'object' has type [object] which doesn't appear to be a range type"
      }
    ],
    "type" : "exception",
    "reason" : "Field 'object' has type [object] which doesn't appear to be a range type"
  },
  "status" : 500
}
```



### Logs (if relevant)

_No response_
x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java
} else {
                parent.append(".");
            }
            parent.append(fieldPart);
        }
    }
    private XContentBuilder resolveEnrichMapping(final EnrichPolicy enrichPolicy, final List<Map<String, Object>> mappings) {
        if (EnrichPolicy.MATCH_TYPE.equals(enrichPolicy.getType())) {
            return createEnrichMappingBuilder((builder) -> builder.field("type", "keyword").field("doc_values", false));
        } else if (EnrichPolicy.RANGE_TYPE.equals(enrichPolicy.getType())) {
            return createRangeEnrichMappingBuilder(enrichPolicy, mappings);
        } else if (EnrichPolicy.GEO_MATCH_TYPE.equals(enrichPolicy.getType())) {
            return createEnrichMappingBuilder((builder) -> builder.field("type", "geo_shape"));
        } else {
            throw new ElasticsearchException("Unrecognized enrich policy type [{}]", enrichPolicy.getType());
        }
    }
    private XContentBuilder createRangeEnrichMappingBuilder(EnrichPolicy enrichPolicy, List<Map<String, Object>> mappings) {
        String matchFieldPath = "properties." + enrichPolicy.getMatchField().replace(".", ".properties.");
        List<Map<String, String>> matchFieldMappings = mappings.stream()
            .map(map -> ObjectPath.<Map<String, String>>eval(matchFieldPath, map))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
        Set<String> types = matchFieldMappings.stream().map(map -> map.get("type")).collect(Collectors.toSet());
        if (types.size() == 1) {
            String type = types.iterator().next();
            switch (type) {
                case "integer_range":
                case "float_range":
                case "long_range":