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