POST activity_skc/_search
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"brandAgg": {
"terms": {
"field": "brand_id",
"size": 20,
"order": {
"sumSoldCount": "desc"
}
},
"aggs": {
"sumSoldCount": {
"sum": {
"field": "sold_num"
}
},
"minDiscountNum": {
"min": {
"script": {
"lang": "painless",
"source": " doc['ypc_price'].value/doc['market_price'].value * 10"
}
}
},
"maxDiscountNum": {
"max": {
"script": {
"lang": "expression",
"source": "doc['ypc_price']/doc['market_price']*10"
}
}
},
"tophits": {
"top_hits": {
"_source": [
"brand_id",
"brand_name",
"ypc_price",
"market_price"
],
"size": 1
}
}
}
}
}
}