Sorting ES按多值字段中特定值的存在进行排序
我需要排序-第一个按“可用”中“商店1”的存在排序,第二个按“价格”升序排序 { "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 { “pID”:1, “可用”:[“车间1”、“车间3”], “价格”:100 } { “pID”:2 “可用”:[“车间2”、“车间4”], “价格”:50 } { “pID”:3, “可用”:[“店铺1”], “价格”:200 } { “pID”:4, “可用”:[“商店4”], “价格”:10 } 结果是pID:1,3,4,2Sorting ES按多值字段中特定值的存在进行排序,sorting,elasticsearch,Sorting,elasticsearch,我需要排序-第一个按“可用”中“商店1”的存在排序,第二个按“价格”升序排序 { "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"
我相信下面这样的方法应该会奏效 这里,如果商店_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"
}
}
]
}
}
}