Hi!
I have documents in elastic like:
{
"email": "user@example.com",
"subject": "Email subject",
"body": "Email body"
}
And I'm trying to count all unique emails that have more than 10 documents.
I can retrieve all such emails by the aggregation query:
GET emails/_search
{
"size": 0,
"aggs": {
"email_with_more_than_10_docs": {
"terms": {
"field": "email",
"min_doc_count": 10
}
}
}
}
And I get the output:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 74,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"email_with_more_than_10_docs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "user1@example.com",
"doc_count" : 40
},
{
"key" : "user2@example.com",
"doc_count" : 14
},
{
"key" : "user3@example.com",
"doc_count" : 13
}
]
}
}
}
But how can I get the number of the unique emails (number of buckets)? In the example of output above that number is 3.