ElasticSearch聚合查詢
1.group distinct
參數:Set
返回結果:Map<Long, Set>
select distinct(playCategory) group by uid
{
"from": 0,
"size": 1,
"query": {
"bool": {
"filter": [
{
"terms": {
"uid": [
"1835212121800011",
"1835212105600007"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": {
"includes": [
"playCategory.keyword"
],
"excludes": []
},
"aggregations": {
"group_info": {
"terms": {
"field": "uid"
},
"aggregations": {
"distinct_info": {
"terms": {
"field": "playCategory.keyword"
}
}
}
}
}
}
查詢結果如下
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 267,
"max_score": 0,
"hits": [
{
"_index": "bixin_playmate_order",
"_type": "bixin_playmate_order",
"_id": "50942322",
"_score": 0,
"_source": {
}
}
]
},
"aggregations": {
"group_info": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1835212121800011,
"doc_count": 221,
"distinct_info": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "d2525eb038dfcf29ae1d3d2eb65d076c",
"doc_count": 78
},
{
"key": "c",
"doc_count": 63
},
{
"key": "587b8da9b832b013e2aca3e171aae07c",
"doc_count": 43
},
{
"key": "b2f36bbf94624eda70367bb5146e8bcf",
"doc_count": 22
},
{
"key": "8efb76c4477637c4c70352b8ce2be686",
"doc_count": 8
},
{
"key": "471028758308978688",
"doc_count": 3
},
{
"key": "bf78dd67d648dc541dff0dc86f8af718",
"doc_count": 2
},
{
"key": "08f02ad405f2433f81774780c5f45a73",
"doc_count": 1
},
{
"key": "8efb76c4477637c4c70352b8ce2be687",
"doc_count": 1
}
]
}
},
{
"key": 1835212105600007,
"doc_count": 46,
"distinct_info": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "d2525eb038dfcf29ae1d3d2eb65d076c",
"doc_count": 16
},
{
"key": "8efb76c4477637c4c70352b8ce2be686",
"doc_count": 12
},
{
"key": "bf78dd67d648dc541dff0dc86f8af718",
"doc_count": 9
},
{
"key": "b2f36bbf94624eda70367bb5146e8bcf",
"doc_count": 6
},
{
"key": "067aeaa0542ebd54881f1de5ac66ae0b",
"doc_count": 1
},
{
"key": "471028758308978688",
"doc_count": 1
},
{
"key": "bfd0af06fe612a5e7348b5718d1da7a2",
"doc_count": 1
}
]
}
}
]
}
}
}