In terms aggregation we can limit the number of buckets using the size parameter but then we are not sure how much buckets exist.
Or we will need to do a separate count aggregation to find this.
Kindly return the total number of distinct terms in the response.
Hi @Vineeth-Mohan
Each aggregation is intended to be "minimal". If you want to know how many distinct values there are, you can add a value_count
aggregation:
GET /_search
{
"aggs": {
"top_terms": {
"terms": {
"field": "foo"
}
},
"total_terms": {
"value_count": {
"field": "foo"
}
}
}
}
See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html#search-aggregations-metrics-valuecount-aggregation
@clintongormley: For distinct values, I believe you'd need to use a cardinality
aggregation, not value_count
:
GET /_search
{
"aggs": {
"top_terms": {
"terms": {
"field": "foo"
}
},
"distinct_terms": {
"cardinality": {
"field": "foo"
}
}
}
}
Most helpful comment
@clintongormley: For distinct values, I believe you'd need to use a
cardinality
aggregation, notvalue_count
: