[英]Elasticsearch sort on multiple queries
我有這樣的查詢:
{
"sort": [
{
"_geo_distance": {
"geo": {
"lat": 39.802763999999996,
"lon": -105.08748399999999
},
"order": "asc",
"unit": "mi",
"mode": "min",
"distance_type": "sloppy_arc"
}
}
],
"query": {
"bool": {
"minimum_number_should_match": 0,
"should": [
{
"match": {
"name": ""
}
},
{
"match": {
"credit": true
}
}
]
}
}
}
我希望我的搜索始終返回所有結果,僅將那些具有匹配標志的結果排序為最接近頂部的結果。
我希望排序優先級如下:
如何做到這一點?
到目前為止,您在上面看到的查詢就是我所得到的。 我一直無法弄清楚如何始終返回所有結果,也無法將其他查詢合並到排序中。
實際上,我不認為“排序”是您要找的答案。 我相信您需要一個反復試驗的方法,從簡單的“布爾”查詢開始,在該查詢中放置所有條件(名稱,標志,距離)。 然后,給您的名稱標准更多的權重(增強),然后給您的標志更少的權重,甚至更少的距離計算。
一個“布爾”“應該”將能夠根據每個_score為您提供一系列文檔列表,並且根據您對每個標准的評分方式,該_score或多或少會受到影響。
同樣,返回所有元素並不困難:只需在您的“布爾”“應該”查詢中添加"match_all": {}
。
從我的角度來看,這將是一個起點,並且,根據您的文檔和您的要求(請參閱我對您的困惑的評論),您需要調整“提升”值並進行測試,再次調整和測試再次等:
{
"query": {
"bool": {
"should": [
{ "constant_score": {
"boost": 6,
"query": {
"match": { "name": { "query": "something" } }
}
}},
{ "constant_score": {
"boost": 3,
"query": {
"match": { "credit": { "query": true } }
}
}},
{ "constant_score": {
"boost": 3,
"query": {
"match": { "atm": { "query": false } }
}
}},
{ "constant_score": {
"boost": 3,
"query": {
"match": { "ada": { "query": true } }
}
}},
{ "constant_score": {
"query": {
"function_score": {
"functions": [
{
"gauss": {
"geo": {
"origin": {
"lat": 39.802763999999996,
"lon": -105.08748399999999
},
"offset": "2km",
"scale": "3km"
}
}
}
]
}
}
}
},
{
"match_all": {}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.