gpt4 book ai didi

elasticsearch - 术语聚合上 doc_count 的范围过滤器

转载 作者:行者123 更新时间:2023-11-29 02:52:24 34 4
gpt4 key购买 nike

{
"size": 0,
"aggs": {
"categories_agg": {
"terms": {
"field": "categories",
"order": {
"_count": "desc"
}
}
}
}
}

为了获取特定字段的聚合,我使用了上面给出的查询。它工作正常并给出如下结果:

{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 77445,
"max_score": 0,
"hits": []
},
"aggregations": {
"categories_agg": {
"doc_count_error_upper_bound": 794,
"sum_other_doc_count": 148316,
"buckets": [
{
"key": "Restaurants",
"doc_count": 25071
},
{
"key": "Shopping",
"doc_count": 11233
},
{
"key": "Food",
"doc_count": 9250
},
{
"key": "Beauty & Spas",
"doc_count": 6583
},
{
"key": "Health & Medical",
"doc_count": 5121
},
{
"key": "Nightlife",
"doc_count": 5088
},
{
"key": "Home Services",
"doc_count": 4785
},
{
"key": "Bars",
"doc_count": 4328
},
{
"key": "Automotive",
"doc_count": 4208
},
{
"key": "Local Services",
"doc_count": 3468
}
]
}
}
}

有没有一种方法可以过滤聚合,以便在每个桶的 doc_count 上获取特定范围内的桶?

例如对 doc_count 使用范围过滤器,其中最大值是 25000,最小值是 5000 应该给我

{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 77445,
"max_score": 0,
"hits": []
},
"aggregations": {
"categories_agg": {
"doc_count_error_upper_bound": 794,
"sum_other_doc_count": 148316,
"buckets": [
{
"key": "Shopping",
"doc_count": 11233
},
{
"key": "Food",
"doc_count": 9250
},
{
"key": "Beauty & Spas",
"doc_count": 6583
},
{
"key": "Health & Medical",
"doc_count": 5121
},
{
"key": "Nightlife",
"doc_count": 5088
}
]
}
}
}

最佳答案

我通过 buckets_selector 解决了这个问题。 我们可以在脚本中过滤计数。

```
"aggs": {
"categories_agg": {
"terms": {
"field": "cel_num",
"size": 5000,
"min_doc_count":1
},
"aggs": {
"count_bucket_selector": {
"bucket_selector": {
"buckets_path": {
"count": "_count"
},
"script": {
"lang":"expression",
"inline": "count>5000 && count <10000"
}
}
}
}
}
}
```

关于elasticsearch - 术语聚合上 doc_count 的范围过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37504179/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com