### 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/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java
assertThat(enrichDocument.get("zipcode"), is(equalTo(90210)));
        
        validateSegments(createdEnrichIndex, 1);
        
        ensureEnrichIndexIsReadOnly(createdEnrichIndex);
    }
    private GetIndexResponse getGetIndexResponseAndCheck(String createdEnrichIndex) {
        GetIndexResponse enrichIndex = client().admin().indices().getIndex(new GetIndexRequest().indices(".enrich-test1")).actionGet();
        assertThat(enrichIndex.getIndices().length, equalTo(1));
        assertThat(enrichIndex.getIndices()[0], equalTo(createdEnrichIndex));
        Settings settings = enrichIndex.getSettings().get(createdEnrichIndex);
        assertNotNull(settings);
        assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all")));
        return enrichIndex;
    }
    public void testRunnerRangeTypeWithIpRange() throws Exception {
        final String sourceIndexName = "source-index";
        createIndex(sourceIndexName, Settings.EMPTY, "_doc", "subnet", "type=ip_range");
        IndexResponse indexRequest = client().index(new IndexRequest().index(sourceIndexName).id("id").source("""
            {"subnet":"10.0.0.0/8","department":"research"}""", XContentType.JSON).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE))
            .actionGet();
        assertEquals(RestStatus.CREATED, indexRequest.status());
        GetIndexResponse sourceIndex = client().admin().indices().getIndex(new GetIndexRequest().indices(sourceIndexName)).actionGet();
        
        Map<String, Object> sourceIndexMapping = sourceIndex.getMappings().get(sourceIndexName).sourceAsMap();
        Map<?, ?> sourceIndexProperties = (Map<?, ?>) sourceIndexMapping.get("properties");
        Map<?, ?> subnetField = (Map<?, ?>) sourceIndexProperties.get("subnet");
        assertNotNull(subnetField);
        assertThat(subnetField.get("type"), is(equalTo("ip_range")));
        SearchResponse sourceSearchResponse = client().search(