gpt4 book ai didi

elasticsearch - ElasticSearch根据存储桶长度(存储桶中唯一键的数量)过滤结果

转载 作者:行者123 更新时间:2023-12-02 22:48:13 26 4
gpt4 key购买 nike

我想写下一个仅在其内部存储桶的长度大于1时才返回键的 flex 聚合。

"aggs": {
"product_definitions": {
"terms": {
"field": "definition_name",
"size": 200,
"exclude": "NO_MATCH",
"min_doc_count": 5
},
"aggs": {
"product_instances": {
"terms": {
"field": "data_source_name",
"size": 100
}
}
}
}
}

这是我的汇总,它返回:
"aggregations": {
"product_definitions": {
"doc_count_error_upper_bound": 10,
"sum_other_doc_count": 29281,
"buckets": [
{
"key": "DANA ANTRİKOT KG",
"doc_count": 13,
"product_instances": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "SariyerMarketCom",
"doc_count": 13
}
]
}
},
{
"key": "Keskinoğlu Piliç Salam 700G",
"doc_count": 10,
"product_instances": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "HappyCenterComTr",
"doc_count": 9
},
{
"key": "SanalMarketComTr",
"doc_count": 1
}
]
}
},
{
"key": "Doğuş Filiz Çayı 1000 G",
"doc_count": 9,
"product_instances": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "HappyCenterComTr",
"doc_count": 7
},
{
"key": "SanalMarketComTr",
"doc_count": 2
}
]
}
}
]
}
}

仅在产品定义存储桶中有两个以上键的情况下,才需要产品定义中的键。在此示例中,它应仅返回2和3.键,而不返回1,因为1.键的存储桶仅包含1个键,即
"buckets": [
{
"key": "SariyerMarketCom",
"doc_count": 13
}
]

最佳答案

您可以利用 bucket_selector pipeline aggregations实现此目的,如下所示:

"aggs": {
"product_definitions": {
"terms": {
"field": "definition_name",
"size": 200,
"exclude": "NO_MATCH",
"min_doc_count": 5
},
"aggs": {
"product_instances": {
"terms": {
"field": "data_source_name",
"size": 100
}
},
"minimum_2": {
"bucket_selector": {
"buckets_path": {
"count": "product_instances._bucket_count"
},
"script": "params.count >= 2"
}
}
}
}
}

关于elasticsearch - ElasticSearch根据存储桶长度(存储桶中唯一键的数量)过滤结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54194338/

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