gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中过滤和求和结果

转载 作者:行者123 更新时间:2023-12-03 01:30:50 24 4
gpt4 key购买 nike

如何在elasticsearch中过滤aggs数据

我用我的条件聚集了文档并成功获得了结果。但我不知道如何过滤结果文档数

这是我的DSL

{
"size": 0,
"query": {
"bool": {
"filter": [
{
"term": {
"company": "ailsx"
}
}
]
}
},
"aggs": {
"date_aggs": {
"terms": {
"field": "date",
"size": 30
},
"aggs": {
"wang": {
"terms": {
"field": "customer"
}
}
}
}
}
}

这是我的结果
{
"took": 1864,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 378426,
"max_score": 0,
"hits": [

]
},
"aggregations": {
"date_aggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1553212800000,
"key_as_string": "2019-03-22 00:00:00",
"doc_count": 107879,
"wang": {
"doc_count_error_upper_bound": 10,
"sum_other_doc_count": 107855,
"buckets": [
{
"key": "sfa",
"doc_count": 4
},
{
"key": "237692469",
"doc_count": 3
},
{
"key": "fasf",
"doc_count": 3
},
{
"key": "1111daaa",
"doc_count": 2
},
{
"key": "2011",
"doc_count": 2
}]}}]}}

我想过滤大于2的doc_count并求和,像这样

从文档中选择Count()
GROUP BY日期,客户HAVING count()> = 2

最佳答案

您可以为此使用min_doc_count:

    "wang": {
"terms": {
"field": "customer",
"min_doc_count": 2 <-- add this
}
}

然后,存储桶的 doc_count属性将成为您的总和。

关于elasticsearch - 如何在Elasticsearch中过滤和求和结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074140/

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