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/main/java/org/elasticsearch/xpack/esql/planner/AggregateMapper.java
AggregateMapper() {
        this(AGG_FUNCTIONS.stream().filter(Predicate.not(SurrogateExpression.class::isAssignableFrom)).toList());
    }
    AggregateMapper(List<? extends Class<? extends Function>> aggregateFunctionClasses) {
        mapper = aggregateFunctionClasses.stream()
            .flatMap(AggregateMapper::typeAndNames)
            .flatMap(AggregateMapper::groupingAndNonGrouping)
            .collect(Collectors.toUnmodifiableMap(aggDef -> aggDef, AggregateMapper::lookupIntermediateState));
    }
    public List<? extends NamedExpression> mapNonGrouping(List<? extends Expression> aggregates) {
        return doMapping(aggregates, false);
    }
    public List<? extends NamedExpression> mapNonGrouping(Expression aggregate) {
        return map(aggregate, false).toList();
    }
    public List<? extends NamedExpression> mapGrouping(List<? extends Expression> aggregates) {
        return doMapping(aggregates, true);
    }
    private List<? extends NamedExpression> doMapping(List<? extends Expression> aggregates, boolean grouping) {
        AttributeMap<NamedExpression> attrToExpressions = new AttributeMap<>();
        aggregates.stream().flatMap(agg -> map(agg, grouping)).forEach(ne -> attrToExpressions.put(ne.toAttribute(), ne));
        return attrToExpressions.values().stream().toList();
    }
    public List<? extends NamedExpression> mapGrouping(Expression aggregate) {
        return map(aggregate, true).toList();
    }
    private Stream<? extends NamedExpression> map(Expression aggregate, boolean grouping) {
        aggregate = unwrapAlias(aggregate);
        return cache.computeIfAbsent(aggregate, aggKey -> computeEntryForAgg(aggKey, grouping)).stream();
    }