es分组排序和聚合后再筛选

GET qx_yisdk_user-yisdk_role/_search
{
    "query": {
        "bool": {
            "filter": [
                {
                    "term": {
                        "game_id": {
                            "value": "230"
                        }
                    }
                },
                {
                    "term": {
                        "vip_auth_check": {
                            "value": "3"
                        }
                    }
                }
            ]
        }
    },
    "size": 10000,
    "aggs": {
        "my_buckets": {
            "terms": {
                "script": {
                    "source": "doc['game_id'].value +'-'+ doc['role_id'].value"
                },
                "size": 60000
            },
            "aggs": {
                "detail": {
                    "top_hits": {
                        "_source": [
                            "*"
                        ],
                        "size": 1,
                        "sort": [
                          {
                            "last_login_time": "desc"
                          }
                      
                        ]
                    }
                },
                "total_money": {
                    "sum": {
                        "field": "charge_money"
                    }
                },
                "max_last_login_time": {
                    "max": {
                        "field": "last_login_time"
                    }
                },
                "sales_bucket_filter": {
                    "bucket_selector": {
                        "buckets_path": {
                            "total_money": "total_money",
                            "max_last_login_time": "max_last_login_time"
                        },
                        "script": "params.total_money >= 1000"
                    }
                }
            }
        }
    }
}

 

posted @ 2022-04-21 09:49  勿回头  阅读(1135)  评论(0编辑  收藏  举报