[英]Elasticsearch. Using term aggregation, return values where doc count is less than some value
I want to group values by field(account id in my case) using term aggregation and return only fields where doc_count is less than some value. 我想使用术语汇总按字段(在我的情况下为帐户ID)将值分组,并且仅返回doc_count小于某个值的字段。
I can specify min_doc_count parameter, but there is no max_doc_count. 我可以指定min_doc_count参数,但是没有max_doc_count。 So I'm looking for a way to simulate this behavior.
因此,我正在寻找一种模拟此行为的方法。 One of my many tries is this, but it doesn't work.
我的许多尝试之一是这样做,但它不起作用。
{
"size": 0,
"aggs": {
"by_account": {
"terms": {
"field": "accountId"
},
"aggs": {
"by_account_filtered": {
"bucket_selector": {
"buckets_path": {
"totalDocs": "_count"
},
"script": "params.totalDocs < 10000"
}
}
}
}
}
}
What am I doing wrong? 我究竟做错了什么?
The bucket_selector aggregation need to be nested ( since its a parent-type aggregation ) and sibling of a metric aggregation that it will use to filter buckets. bucket_selector聚合需要嵌套(因为它是父类型的聚合 ),并且需要嵌套用于过滤存储桶的度量标准聚合。
So we use a top level terms
aggregation, then use a nested value_count
aggregation to expose the bucket doc_count to the sibling selector_bucket
aggregation 因此,我们使用顶级
terms
聚合,然后使用嵌套的value_count
聚合将存储桶doc_count暴露给同级的selector_bucket
聚合
try this : 尝试这个 :
{
"size": 0,
"aggs": {
"by_account": {
"terms": {
"field": "accountId"
},
"aggs": {
"by_account_number": {
"value_count" : {
"field" : "accountId"
}
},
"by_account_filtered": {
"bucket_selector": {
"buckets_path": {
"totalDocs": "by_account_number"
},
"script": "params.totalDocs < 10000"
}
}
}
}
}
}
EDIT : If you want to get the lowest account doc_count 编辑:如果您想获得最低的帐户doc_count
{
"size": 0,
"aggs": {
"by_account": {
"terms": {
"field": "accountId",
"order" : { "_count" : "asc" },
"size": 100
},
"aggs": {
"by_account_number": {
"value_count" : {
"field" : "accountId"
}
},
"by_account_filtered": {
"bucket_selector": {
"buckets_path": {
"totalDocs": "by_account_number"
},
"script": "params.totalDocs < 10000"
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.