When using the terms enum API on a constant keyword field, an error is returned complaining about a non-null value.

Request:

```
POST /metrics-endpoint.policy-default/_terms_enum
{
  "field": "data_stream.type"
}
```

Response:

```
#! Your license will expire in [5] days. Contact your administrator or update your license for continued use of features
#! Your license will expire in [6] days. Contact your administrator or update your license for continued use of features
{
  "_shards" : {
    "total" : 8,
    "successful" : 4,
    "failed" : 4,
    "failures" : [
      {
        "shard" : 0,
        "index" : ".ds-metrics-endpoint.policy-default-2022.04.04-000001",
        "status" : "INTERNAL_SERVER_ERROR",
        "reason" : {
          "type" : "broadcast_shard_operation_failed_exception",
          "reason" : """java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because "this.value" is null
	at org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper$ConstantKeywordFieldType.getTerms(ConstantKeywordFieldMapper.java:156)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.dataNodeOperation(TransportTermsEnumAction.java:351)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.lambda$asyncNodeOperation$0(TransportTermsEnumAction.java:712)
	at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:47)
	at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:62)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:773)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
""",
          "index_uuid" : "uOdQ_uBRRLeq5-OAJAwGrg",
          "shard" : "0",
          "index" : ".ds-metrics-endpoint.policy-default-2022.04.04-000001"
        }
      },
      {
        "shard" : 0,
        "index" : ".ds-metrics-endpoint.policy-default-2022.04.07-000002",
        "status" : "INTERNAL_SERVER_ERROR",
        "reason" : {
          "type" : "broadcast_shard_operation_failed_exception",
          "reason" : """java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because "this.value" is null
	at org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper$ConstantKeywordFieldType.getTerms(ConstantKeywordFieldMapper.java:156)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.dataNodeOperation(TransportTermsEnumAction.java:351)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.lambda$asyncNodeOperation$0(TransportTermsEnumAction.java:712)
	at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:47)
	at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:62)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:773)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
""",
          "index_uuid" : "qBOOM6CXRpuK0budYXBUnQ",
          "shard" : "0",
          "index" : ".ds-metrics-endpoint.policy-default-2022.04.07-000002"
        }
      },
      {
        "shard" : 0,
        "index" : ".ds-metrics-endpoint.policy-default-2022.04.22-000007",
        "status" : "INTERNAL_SERVER_ERROR",
        "reason" : {
          "type" : "broadcast_shard_operation_failed_exception",
          "reason" : """java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because "this.value" is null
	at org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper$ConstantKeywordFieldType.getTerms(ConstantKeywordFieldMapper.java:156)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.dataNodeOperation(TransportTermsEnumAction.java:351)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.lambda$asyncNodeOperation$0(TransportTermsEnumAction.java:712)
	at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:47)
	at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:62)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:773)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
""",
          "index_uuid" : "e8KIwULjSsSn3NGdm7tuPw",
          "shard" : "0",
          "index" : ".ds-metrics-endpoint.policy-default-2022.04.22-000007"
        }
      },
      {
        "shard" : 0,
        "index" : ".ds-metrics-endpoint.policy-default-2022.04.25-000008",
        "status" : "INTERNAL_SERVER_ERROR",
        "reason" : {
          "type" : "broadcast_shard_operation_failed_exception",
          "reason" : """java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because "this.value" is null
	at org.elasticsearch.xpack.constantkeyword.mapper.ConstantKeywordFieldMapper$ConstantKeywordFieldType.getTerms(ConstantKeywordFieldMapper.java:156)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.dataNodeOperation(TransportTermsEnumAction.java:351)
	at org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction.lambda$asyncNodeOperation$0(TransportTermsEnumAction.java:712)
	at org.elasticsearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:47)
	at org.elasticsearch.action.ActionRunnable$2.doRun(ActionRunnable.java:62)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:773)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
""",
          "index_uuid" : "bDskzrgwQbG35K389_yyKA",
          "shard" : "0",
          "index" : ".ds-metrics-endpoint.policy-default-2022.04.25-000008"
        }
      }
    ]
  },
  "terms" : [
    "metrics"
  ],
  "complete" : false
}
```
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java
Set<BytesReference> queries = indexAccessControl.getDocumentPermissions().getQueries();
                    for (BytesReference querySource : queries) {
                        QueryBuilder queryBuilder = DLSRoleQueryValidator.evaluateAndVerifyRoleQuery(
                            querySource,
                            scriptService,
                            queryShardContext.getParserConfig().registry(),
                            securityContext.getUser()
                        );
                        QueryBuilder rewrittenQueryBuilder = Rewriteable.rewrite(queryBuilder, queryShardContext);
                        if (rewrittenQueryBuilder instanceof MatchAllQueryBuilder) {
                            
                            return true;
                        }
                    }
                    return false;
                }
            }
        }
        return true;
    }
    private boolean canMatchShard(ShardId shardId, NodeTermsEnumRequest req) throws IOException {
        if (req.indexFilter() == null || req.indexFilter() instanceof MatchAllQueryBuilder) {
            return true;
        }
        ShardSearchRequest searchRequest = new ShardSearchRequest(shardId, req.nodeStartedTimeMillis(), AliasFilter.EMPTY);
        searchRequest.source(new SearchSourceBuilder().query(req.indexFilter()));
        return searchService.canMatch(searchRequest).canMatch();
    }
    protected class AsyncBroadcastAction {