Count distinct on elastic search

elasticsearch, elasticsearch-plugin

Solution

  {
      "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

Problem

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.

Original source