沙师弟,师父的充电器掉了

es 相对于 group by haveing 有没有什么类似的方法实现

Elasticsearch | 作者 devilhookey | 发布于2016年11月09日 | 阅读数:3568

RT
类似 group by,每个group获取3条记录,如果少于3条的,有多少条返回多少条记录
已邀请:

strglee - 公众号: 每日ELK ,每天分享ELK相关知识

赞同来自: devilhookey

 
"aggs": {
"blog_group":{
"terms": {
"field":"user_id",
"size": 0
},
"aggs": {
"having": {
"bucket_selector": {
"buckets_path": {
"blog_count": "_count"
},
"script": {
"lang": "expression",
"inline": " blog_count < 3"
}
}
}
}
}
}

  1. [/url]

devilhookey

赞同来自:

{
"query": {
"multi_match": {
"query": "差点什么",
"fields": [
"title",
"name",
"remark",
"username",
"other"
],
"analyzer": "ik_syno_smart",
"minimum_should_match": "90%"
}
},
"min_score": 1,
"sort": [
{
"uid": {
"order": "asc"
}
}
],
"aggs": {
"uids": {
"terms": {
"field": "uid",
"size": 0
},
"aggs": {
"having": {
"bucket_selector": {
"buckets_path": {
"uids_count": "_count"
},
"script": {
"lang": "expression",
"inline": "uids_count < 3"
}
}
}
}
}
},
"size": 100
}
然而结果还是有超过3条重复的uid数据

要回复问题请先登录注册