我一直在尝试在弹性搜索中的查询中获得独特的结果。下面给出了我编写的查询。我正在尝试找到一种解决方案,以便在名为“便士”的领域获得独特的结果。预先感谢。
{
"query": {
"exists": {
"field": "penny"
}
}
}
}
尝试
terms
聚合
您的文件
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}
查询
GET /unique_results/_search?filter_path=aggregations
{
"aggs": {
"by_penny": {
"terms": {
"field": "penny",
"size": 10
}
}
}
}
回应
{
"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
}
]
}
}
}