Elastic Search 權重及排序搜索結果中 _score 字段為 null


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": "諾心"
            }
          }
        }
      ]
    }
  }
}

  

elasticsearch 權重及排序

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM