Node.js 基于多个查询的Elasticsearch排序
我有这样一个问题:Node.js 基于多个查询的Elasticsearch排序,node.js,sorting,
elasticsearch,search-engine,Node.js,Sorting,
elasticsearch,Search Engine,我有这样一个问题: { "sort": [ { "_geo_distance": { "geo": { "lat": 39.802763999999996, "lon": -105.08748399999999 }, "order": "asc",
{
"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
}
}
]
}
}
}
我希望我的搜索总是返回所有结果,只是与那些匹配的标志更接近顶部的结果排序
我希望排序优先级如下所示:
“match_ALL”:{}
从我的观点来看,这将是一个起点,并且,根据您的文档和要求(请参阅我对您文章中关于混淆的评论),您需要调整“boost”值并进行测试,再次调整并再次测试,等等:
{
"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": {}
}
]
}
}
}
你的要求有点混乱。你说“那些有匹配标志的”应该“更接近顶部”。但您的排序优先级将“名称”作为最高排序标准。因此,它应该首先找到所有匹配的名称,然后考虑匹配标志的数量(匹配标志越多越好)?假设你想搜索一家银行分行——你想让名称与该分行具有“信用”功能、“atm”功能这一事实更加匹配?或者您想找到具有“好”名称和一些“好”功能的分支?意思是名称和这些功能有多重要?