Elasticsearch, how to get all unique values of a field and count of total unique values? Elasticsearch, how to get all unique values of a field and count of total unique values? elasticsearch elasticsearch

Elasticsearch, how to get all unique values of a field and count of total unique values?


If you use Elasticsearch 1.1.0 or above, you can try to estimate the distinct counts with cardinal aggregations.

A simple query would look like this in your case:

POST /{yourIndex}/{yourType}/_search{    "aggs" : {        "company_count" : {            "cardinality" : {                "field" : "company.company_raw",                "precision_threshold": 10000            }        }    }}