### 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
}
    private void waitForIndexGreen(final String destinationIndexName) {
        ClusterHealthRequest request = new ClusterHealthRequest(destinationIndexName).waitForGreenStatus();
        enrichOriginClient().admin()
            .cluster()
            .health(request, listener.delegateFailure((l, r) -> updateEnrichPolicyAlias(destinationIndexName)));
    }
    private void updateEnrichPolicyAlias(final String destinationIndexName) {
        String enrichIndexBase = EnrichPolicy.getBaseName(policyName);
        logger.debug("Policy [{}]: Promoting new enrich index [{}] to alias [{}]", policyName, destinationIndexName, enrichIndexBase);
        GetAliasesRequest aliasRequest = new GetAliasesRequest(enrichIndexBase);
        ClusterState clusterState = clusterService.state();
        String[] concreteIndices = indexNameExpressionResolver.concreteIndexNamesWithSystemIndexAccess(clusterState, aliasRequest);
        String[] aliases = aliasRequest.aliases();
        IndicesAliasesRequest aliasToggleRequest = new IndicesAliasesRequest();
        String[] indices = clusterState.metadata().findAliases(aliases, concreteIndices).keySet().toArray(new String[0]);
        if (indices.length > 0) {
            aliasToggleRequest.addAliasAction(IndicesAliasesRequest.AliasActions.remove().indices(indices).alias(enrichIndexBase));
        }
        aliasToggleRequest.addAliasAction(IndicesAliasesRequest.AliasActions.add().index(destinationIndexName).alias(enrichIndexBase));
        enrichOriginClient().admin().indices().aliases(aliasToggleRequest, listener.delegateFailure((l, r) -> {
            logger.info("Policy [{}]: Policy execution complete", policyName);
            ExecuteEnrichPolicyStatus completeStatus = new ExecuteEnrichPolicyStatus(ExecuteEnrichPolicyStatus.PolicyPhases.COMPLETE);
            task.setStatus(completeStatus);
            l.onResponse(completeStatus);
        }));
    }
    /**
     * Use this client to access information at the access level of the Enrich plugin, rather than at the access level of the user.
     * For example, use this client to access system indices (such as `.enrich*` indices).