我需要排序 - 第一个是“shop_1”存在于“available”中,第二个是“price”升序。
{ "pID": 1, "available": ["shop_1", "shop_3"], "price": 100 } { "pID": 2 "available": ["shop_2", "shop_4"], "price": 50 } { "pID": 3, "available": ["shop_1"], "price": 200 } { "pID": 4, "available": ["shop_4"], "price": 10 } So the result would be pID: 1, 3, 4, 2
答案 0 :(得分:0)
我相信下面的内容应该有效
如果shop_1可用,那么我们将得分提高10,这将高于价格领域的任何倒数。 这两者的总和将确保我们得到你想要的东西。
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"boost_mode": "replace",
"score_mode": "sum",
"functions": [
{
"filter": {
"term": {
"available": "shop_1"
}
},
"weight": 10
},
{
"field_value_factor": {
"field": "price",
"modifier": "reciprocal"
}
}
]
}
}
}