Elasticsearch doesn't support deterministic DISTINCT counts (source). It supports only approximate distinct counters like "cardinality".
One way to count distincts in a deterministic way is to aggregate them using "terms" and count buckets from result.