按照用户Id分桶后,统计每个id出现的次数之后,如何再按照id出现次数再次分桶,统计某次数范围内包含id的个数
Elasticsearch | 作者 pentakill | 发布于2018年07月31日 | 阅读数:4239
原始数据按照uid分桶以后,获取的数据
uid Count
001 20
002 10
003 70
如何得到如下统计数据?
0<=Count<50 2
50<=Count<100 1
uid Count
001 20
002 10
003 70
如何得到如下统计数据?
0<=Count<50 2
50<=Count<100 1
5 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: rochy
{
"query":{
"terms":{
"authors": ["张三"]
}
},
"size": 0,
"aggs" : {
"authors_agg": {
"terms": {
"field": "authors"
},
"aggs": {
"count_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"cur_doc_cnt": "_count"
},
"script": "params.cur_doc_cnt > 5"
}
}
}
}
}
}
参考举例,bucket_selector试试
kennywu76 - Wood
赞同来自: pentakill
pentakill
赞同来自: felixzxk
POST book_authors/_search
{
"query":{
"terms":{
"authors": ["张三"]
}
},
"size": 0,
"aggs" : {
"authors_agg": {
"terms": {
"field": "authors"
},
"aggs": {
"count_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"cur_doc_cnt": "_count"
},
"script": "params.cur_doc_cnt > 5"
}
},"count":{
"cardinality": {
"field": "authors"
}
}
}
},"total_count":{
"sum_bucket": {
"buckets_path": "authors_agg>count.value"
}
}
}
}
rochy - rochy_he
赞同来自:
pentakill
赞同来自:
"aggs": {
"agregation_by_uid": {
"terms": {
"field": "uid",
"size": 500
}
},
"rang_with_count":{
"range": {
"field": "_count",//这个字段获取不到
"ranges": [
{
"from": 50,
"to": 100
},
{
"from": 0,
"to": 50
}
]
}
}
}