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
.toList();
            var actual = getValuesList(results).stream().map(l -> (Long) l.get(0)).toList();
            assertThat(actual, equalTo(expected));
        }
    }
    /*
     * Create two indices that both have nested documents in them. Create an alias pointing to the two indices.
     * Query an individual index, then query the alias checking that no nested documents are returned.
     */
    public void testReturnNoNestedDocuments() throws IOException, ExecutionException, InterruptedException {
        var indexName1 = "test_nested_docs_1";
        var indexName2 = "test_nested_docs_2";
        var indices = List.of(indexName1, indexName2);
        var alias = "test-alias";
        int docsCount = randomIntBetween(50, 100);
        int[] countValuesGreaterThanFifty = new int[indices.size()];
        for (int i = 0; i < indices.size(); i++) {
            String indexName = indices.get(i);
            createNestedMappingIndex(indexName);
            countValuesGreaterThanFifty[i] = indexDocsIntoNestedMappingIndex(indexName, docsCount);
        }
        createAlias(indices, alias);
        var indexToTest = randomIntBetween(0, indices.size() - 1);
        var indexNameToTest = indices.get(indexToTest);
        
        assertNoNestedDocuments("from " + indexNameToTest, docsCount, 0L, 100L);
        
        assertNoNestedDocuments("from " + indexNameToTest + " | where data >= 50", countValuesGreaterThanFifty[indexToTest], 50L, 100L);
        
        assertNoNestedDocuments("from " + alias, docsCount * 2, 0L, 100L);