POST users/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"course": {
"value": ""
}
}
}
]
}
},
"aggs": {
"item_names": {
"terms": {
"field": "user_name",
"size": 100,
"order": {
"course_count": "desc"
}
},
"aggs": {
"course_count": {
"cardinality": {
"field": "course"
}
},
"orderNumber_count_filter": {
"bucket_selector": {
"buckets_path": {
"orderNumberCount": "course_count"
},
"script": "params.orderNumberCount>6"
}
}
}
}
},
"from": 0,
"size": 0
}
与之对应的mysql语句:
select user_name,count(distinct course) as num from table where course !='' group by user_name having num >6 ORDER BY num DESC