25 相关度分数优化方法

negative boost

GET /forum/article/_search 
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "content": "java"
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "content": "spark"
          }
        }
      ]
    }
  }
}
  • 搜索包含java,不包含spark的doc,但是这样子很死板
  • 搜索包含java,尽量不包含spark的doc,如果包含了spark,不会说排除掉这个doc,而是说将这个doc的分数降低
  • 包含了negative term的doc,分数乘以negative boost,分数降低

 

GET /forum/article/_search 
{
  "query": {
    "boosting": {
      "positive": {
        "match": {
          "content": "java"
        }
      },
      "negative": {
        "match": {
          "content": "spark"
        }
      },
      "negative_boost": 0.2
    }
  }
}

 

constant_score

  不需要相关度评分,直接走constant_score加filter,所有的doc分数都是1,没有评分的概念

GET /forum/article/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "title": "java"
              }
            },
            {
              "term": {
                "title": "spark"
              }
            }
          ]
        }
      }
    }
  }
}

  

 

posted on 2020-12-01 23:35  溪水静幽  阅读(93)  评论(0)    收藏  举报