ElasticSearch聚合查询
1.group distinct
参数:Set
返回结果:Map<Long, Set>
select distinct(playCategory) group by uid
{
"query":{
"bool":{
"filter":[
{
"terms":{
"guid":[
"1835212105600007",
"1835212121800011"
],
"boost":1
}
}
],
"adjust_pure_negative":true,
"boost":1
}
},
"_source":{
"includes":[
"playCategory.keyword"
],
"excludes":[
]
},
"aggregations":{
"group_info":{
"terms":{
"field":"guid",
"size":10,/*group_info 的 limit*/
"min_doc_count":1,
"shard_min_doc_count":0,
"show_term_doc_count_error":false,
"order":[
{
"_count":"desc"
},
{
"_key":"asc"
}
]
},
"aggregations":{
"distinct_info":{
"terms":{
"field":"playCategory.keyword",
"size":10,/*distinct_info的limit*/
"min_doc_count":1,
"shard_min_doc_count":0,
"show_term_doc_count_error":false,
"order":[
{
"_count":"desc"
},
{
"_key":"asc"
}
]
}
}
}
}
}
}
查询结果如下
{
"took":2,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":139,
"max_score":0,
"hits":[
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"42515235",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"50943600",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"50943796",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"42514238",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"42514231",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"50943123",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"42514354",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"42515407",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"50942086",
"_score":0,
"_source":{
}
},
{
"_index":"bixin_playmate_order",
"_type":"bixin_playmate_order",
"_id":"50942161",
"_score":0,
"_source":{
}
}
]
},
"aggregations":{
"group_info":{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":0,
"buckets":[
{
"key":1835212121800011,
"doc_count":79,
"distinct_info":{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":2,
"buckets":[
{
"key":"d2525eb038dfcf29ae1d3d2eb65d076c",
"doc_count":32
},
{
"key":"c",
"doc_count":25
},
{
"key":"b2f36bbf94624eda70367bb5146e8bcf",
"doc_count":13
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc1",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc2",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc3",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc4",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc5",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc6",
"doc_count":1
},
{
"key":"b2f36bbf94624eda70367bb5146e8bc7",
"doc_count":1
}
]
}
},
{
"key":1835212105600007,
"doc_count":60,
"distinct_info":{
"doc_count_error_upper_bound":0,
"sum_other_doc_count":0,
"buckets":[
{
"key":"bf78dd67d648dc541dff0dc86f8af718",
"doc_count":38
},
{
"key":"d2525eb038dfcf29ae1d3d2eb65d076c",
"doc_count":14
},
{
"key":"471028758308978688",
"doc_count":4
},
{
"key":"b2f36bbf94624eda70367bb5146e8bcf",
"doc_count":4
}
]
}
}
]
}
}
}