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
assertNoNestedDocuments("from " + alias + " | where data >= 50", Arrays.stream(countValuesGreaterThanFifty).sum(), 50L, 100L);
    }
    public void testGroupingMultiValueByOrdinals() {
        String indexName = "test-ordinals";
        assertAcked(client().admin().indices().prepareCreate(indexName).setMapping("kw", "type=keyword", "v", "type=long").get());
        int numDocs = randomIntBetween(10, 200);
        for (int i = 0; i < numDocs; i++) {
            Map<String, Object> source = new HashMap<>();
            source.put("kw", "key-" + randomIntBetween(1, 20));
            List<Integer> values = new ArrayList<>();
            int numValues = between(0, 2);
            for (int v = 0; v < numValues; v++) {
                values.add(randomIntBetween(1, 1000));
            }
            if (values.isEmpty() == false) {
                source.put("v", values);
            }
            client().prepareIndex(indexName).setSource(source).get();
            if (randomInt(100) < 20) {
                client().admin().indices().prepareRefresh(indexName).get();
            }
        }
        client().admin().indices().prepareRefresh(indexName).get();
        var functions = List.of("min(v)", "max(v)", "count_distinct(v)", "count(v)", "sum(v)", "avg(v)", "percentile(v, 90)");
        for (String fn : functions) {
            String query = String.format(Locale.ROOT, "from %s | stats s = %s by kw", indexName, fn);
            run(query).close();
        }
    }