Count distinct on elastic search

PravinKumar.R picture PravinKumar.R · Mar 19, 2017 · Viewed 12.4k times · Source

How to achieve count distinct function on elastic search type using sql4es driver?

Select distinct inv_number , count(1) from invoices;

But it returns the total count of the particular invoice number.

Answer

asu picture asu · Jun 12, 2017

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.