Elasticsearch datasource: counting unique items in array


I’m using Grafana 10.0.2 with an Elasticsearch datasource.
I’m trying to count distinct values in a field which is an array.

So for instance, 2 rows of this field are:
row1: “cls”: [“CAT”, “DOG”, “CAT”, “CAT”]
row2: “cls”: [“RAT”, “ANT”, “ANT”]

So I’d like to calculate values:
row1: cat_count=3, dog_count=1,rat_count=0, ant_count=0
row2: cat_count=0, dog_count=0,rat_count=1, ant_count=2

I’ve tried various transform options, such as extract fields, group by etc etc with no success
thank you in advance for any help or suggestions