我需要对后汇总指标进行前n个查询。听起来很简单。这是我正在使用的查询-
{
"queryType": "topN",
"dataSource": "model",
"granularity": "all",
"intervals": [
"2018-01-01T00:00:00/2018-12-31T23:59:59"
],
"dimension": {
"type": "lookup",
"dimension": "COName",
"outputName": "COName",
"name": "COName"
},
"metric": "MarketShare",
"threshold": 10,
"aggregations": [
{
"type": "filtered",
"filter": {
"type": "selector",
"dimension": "Brand",
"value": "Nike"
},
"aggregator": {
"type": "doubleSum",
"name": "nike_sum",
"fieldName": "Sales"
}
},
{
"type": "doubleSum",
"name": "total_sum",
"fieldName": "Sales"
}
],
"postAggregations": [
{
"type": "arithmetic",
"name": "MarketShare",
"fn": "*",
"fields": [
{
"type": "arithmetic",
"name": "div",
"fn": "/",
"fields": [
{
"type": "fieldAccess",
"name": "brand_sum",
"fieldName": "nike_sum"
},
{
"type": "fieldAccess",
"name": "total_sum_1",
"fieldName": "total_sum"
}
]
},
{
"type": "constant",
"name": "const",
"value": 100
}
]
}
],
"context": {
"skipEmptyBuckets": true
}
}
这给了我奇怪的前N个结果(数字不正确)。我敢肯定,因为当我对某些特定的COName进行简单分组时,我得到了预期的结果。
有趣的事实:
当我将"metric": "MarketShare"
替换为诸如"metric": "total_sum"
之类的其他度量标准时,我得到的数字正确,但是排序现在使用“ total_sum”。