Elasticsearch 学习之子聚集过滤

1. 获取子聚合结果总数
{
    "size": 0,
    "aggs": {
        "msisdnAgg": {
            "terms": {
                "field": "msisdn"
            },
            "aggs": {
                "tagAggs": {
                    "terms": {
                        "field": "tags"
                    }
                },
                "sum_of_rul": {
                    "sum_bucket": {
                        "buckets_path": "tagAggs>_count"
                    }
                }
            }
        }
    }
}

2. 获取子聚合结果总数大于指定数

{
    "size": 0,
    "aggs": {
        "msisdnAgg": {
            "terms": {
                "field": "msisdn"
            },
            "aggs": {
                "tagAggs": {
                    "terms": {
                        "field": "tags"
                    }
                },
                "sum_of_rul": {
                    "sum_bucket": {
                        "buckets_path": "tagAggs>_count"
                    }
                },
                "orderNumber_count_filter": {
                    "bucket_selector": {
                        "buckets_path":  {
                            "orderNumberCount": "sum_of_rul"
                        },
                        "script": "orderNumberCount > 2 "
                    }
                }
            }
        }
    }
}

 

posted @ 2019-02-24 22:35  天~宇~翱~翔  阅读(590)  评论(0编辑  收藏  举报