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"
                    }
                }
            }
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM