https://blog.csdn.net/u011915540/article/details/102673883
https://zhuanlan.zhihu.com/p/344770083
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/sort-search-results.html#_script_based_sorting
出现原因
搜索时使用了其他字段作为排序条件,ES
默认是使用 _score
作为排序条件的
解决方案
在 sort
里增加 _score
字段排序
GET bte/_search { "explain": true, "size": 10, "_source": [ "sku_id", "goods_name", "is_show", "common_is_show", "alias_name", "sort_tag" ], "sort": [ { "_script": { "type": "number", "script": { "lang": "painless", "source": " doc['sort_tag'].value + _score * params.factor ", "params": { "factor": 1.1 } }, "order": "desc" }, "_score":{ "order": "desc" } } ], "query": { "bool": { "filter": [ { "terms": { "city_code": [ 1, 304447, 110100 ] } }, { "term": { "is_show": 1 } }, { "term": { "on_sale": 1 } } ], "must": [ { "match": { "goods_name": { "query": "诺心" } } } ] } } }