elasticsearch版本:5.6.16,lucene\u版本:6.6.1
我想按elasticsearch中的聚合字段对点击进行排序。
我想排序的字段是bucket聚合组按item id的savings pct。
有没有办法将字段放入“\u source”以便我可以在排序脚本中使用它?
请注意,查询示例中的重要位是“groupbyitem”和“source”以及“sort”
{
"query": {
"bool": {
"must": [],
"should": [],
"filter": [
{
"terms": {
"item_type": [
"helmets_clothes"
]
}
}
]
}
},
"aggs": {
"min_price_eur": {
"min": {
"field": "item_price_eur",
"missing": 0
}
},
"max_price_eur": {
"max": {
"field": "item_price_eur",
"missing": 0
}
},
"group_by_item_id": {
"terms": {
"field": "same_item_id",
"size": 100
},
"aggs": {
"average_price": {
"avg": {
"field": "item_price_eur"
}
},
"min_price": {
"min": {
"field": "item_price_eur"
}
},
"savings_pct": {
"bucket_script": {
"buckets_path": {
"avg_price": "average_price",
"total_prices": "_count",
"min_price": "min_price"
},
"script": "100-(params.min_price / params.avg_price) * 100"
}
}
}
}
},
"_source": [
"item_url"
],
"sort": [
{
"_script" : {
"type" : "number",
"script" : {
"lang": "painless",
"inline": "doc['prices_count'].value == 5 ? 100 - (doc['min_price_eur'].value / doc['max_price_eur'].value) * 100 : 0"
},
"order" : "asc"
}
}
]
}
暂无答案!
目前还没有任何答案,快来回答吧!