The ES|QL `COUNT_DISTINCT` function fails with an `illegal agg type: text` error when it's run on a `text` field. It's fine with `keyword` fields. Compare to for example `COUNT`, which runs fine on text fields:

```
PUT test/_doc/1
{
  "foo": "bar"
}

# This fails with illegal agg type: text:
POST /_query
{
  "query": """
    FROM test
    | STATS count = COUNT_DISTINCT(foo)
  """
}

# This works:
POST /_query
{
  "query": """
    FROM test
    | STATS count = COUNT_DISTINCT(foo.keyword)
  """
}

# COUNT is fine with text fields:
POST /_query
{
  "query": """
    FROM test
    | STATS count = COUNT(foo)
  """
}
```

Full error message:

```
{
  "error": {
    "root_cause": [
      {
        "type": "esql_illegal_argument_exception",
        "reason": "illegal agg type: text"
      }
    ],
    "type": "esql_illegal_argument_exception",
    "reason": "illegal agg type: text"
  },
  "status": 500
}
```
x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionIT.java
long value = randomLongBetween(1, 1000);
                    client().prepareBulk().add(new IndexRequest(indexName).id("doc-" + i).source("data", 1, "value", value)).get();
                    sum += value;
                }
                totalValues.set(sum);
            }
        });
        indexingThread.start();
        try {
            logger.info("--> waiting for shards to have pending refresh");
            Index index = resolveIndex(indexName);
            latch.countDown();
            assertBusy(() -> {
                int pendingRefreshes = 0;
                for (IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) {
                    IndexService indexService = indicesService.indexService(index);
                    if (indexService != null) {
                        for (IndexShard shard : indexService) {
                            if (shard.hasRefreshPending()) {
                                pendingRefreshes++;
                            }
                        }
                    }
                }
                assertThat("shards don't have any pending refresh", pendingRefreshes, equalTo(numShards));
            }, 30, TimeUnit.SECONDS);
        } finally {
            stopped.set(true);
            indexingThread.join();
        }