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.
There's no support for distinct counting in ElasticSearch, although non-deterministic counting exists. Use "terms" aggregation and count buckets in result. See Count distinct on elastic search question.
You can use a Metric visualization and just use the "count" metric for this. There are many ways to do this, generally in most visualizations, you can: use "Unique Count" on the personId field as the metric. use a terms aggregation on the organizationId field for the X-Axis (or split rows in a table visualization).
Cardinality aggregationedit. A single-value metrics aggregation that calculates an approximate count of distinct values.
{
"size": 0,
"aggs": {
"total_invoices": {
"terms": {
"field": "inv_number"
},
"aggs": {
"unique_invoiceid": {
"cardinality": {
"field": "inv_number"
}
}
}
}
}
This will give you the invoice number as key and distict value in unique_invoiceid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With