I looked around for quite a bit, and I couldn't find an aggregation type in Elasticsearch that can count the unique values of an aggregation output. I'll ask some more and see if I missed something in the documentation: Aggregations | Elasticsearch Guide [6.4] | Elastic
Possibilities with pipeline aggregation also refers to the previous question. I'm not sure if there is a type of pipeline that can pipe the output of one aggregation and count the distinct values that came in.
I think you could use the Elasticsearch input plugin (not filter plugin) in Logstash: Elasticsearch input plugin | Logstash Reference [8.11] | Elastic. The input query would be the aggregation, and you could re-index the results into a new index, then use the new index in Kibana for the visualization.
If you don't have that plugin for Logstash and are not able to get it, you can achieve the same with some custom scripts in a language like Python or NodeJS to run a query, format the results into new documents, and index those into Elasticsearch.