Try the terms aggregation
Your documents
PUT /unique_results/_bulk
{"create":{"_id":1}}
{"penny":400012121312}
{"create":{"_id":2}}
{"penny":400012121312}
{"create":{"_id":3}}
{"penny":400012121396}
{"create":{"_id":4}}
{"penny":400012121334}
{"create":{"_id":5}}
{"penny":400012121334}
Query
GET /unique_results/_search?filter_path=aggregations
{
"aggs": {
"by_penny": {
"terms": {
"field": "penny",
"size": 10
}
}
}
}
Response
{
"aggregations" : {
"by_penny" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 400012121312,
"doc_count" : 2
},
{
"key" : 400012121334,
"doc_count" : 2
},
{
"key" : 400012121396,
"doc_count" : 1
}
]
}
}
}