ES聚合分组后count排序

ES通过多个字段分组后count排序.
数据库SQL:select count(1) from table group by storeCode,productId order by count(1) desc;

{
    "query": {
        "bool": {
            "must": [
                {
                    "exists": {
                        "field": "storeCode"
                    }
                },
                {
                    "bool": {
                        "must_not": {
                            "term": {"storeCode" : ""}
                        }
                    }
                }
            ]
        }
    },
    "size": 0,
    "aggs": {
        "storeCodeAggs": {
            "terms": {
                "field": "storeCode",
                "order": {
                    "_count": "desc"
                }
            },
            "aggs": {
                "prodAggs": {
                    "terms": {
                        "field": "productId"
                    }
                }
            }
        }
    }
}

你可能感兴趣的:(ES聚合分组后count排序)