elasticsearch mapping参数--boost

此文档基于es7.1版本。

boost用于影响返回结果的相关性评分,在原评分基础上*boost值。如果是2的话,就是2倍打分值,如果是0.5就是原打分的一半。

测试如下:其中针对title的get的"_score" : 0.5753642,针对content的get的"_score" : 0.2876821。可以看出来是2倍值。

PUT boost_index
{
  "mappings": {
    "properties": {
      "title":{
        "type": "text",
        "boost": 2
      },
      "content":{
        "type": "text"
      }
    }
  }
}


POST boost_index/_doc
{
  "title":"Quick brown fox jumps lazy dogs!",
  "content":"Quick brown fox jumps lazy dogs!"
}

GET boost_index/_search
{
  "query": {
    "match": {
      "title": "quick"
    }
  }
}

GET boost_index/_search
{
  "query": {
    "match": {
      "content": "quick"
    }
  }
}

boost在5.0版本后改为了检索时计算,在此之前是在文档记录保存的时候计算。可以在检索的时候,带入boost参数,影响评分,与mapping时设置字段属性获得打分的效果一样:其中第一个get获得"_score" : 0.5753642,第二个get获得"_score" : 0.2876821

GET boost_index/_search
{
  "query": {
    "match": {
      "content": {
        "query": "quick",
        "boost": 2
      }
    }
  }
}

GET boost_index/_search
{
  "query": {
    "match": {
      "content": {
        "query": "quick"
      }
    }
  }
}

boost仅对analyzer分词后的单词文本检索有效,对prefix, range and fuzzy queries无效。例如:下面两者的打分均为"_score" : 0.23014566。boost不起作用。

GET boost_index/_search
{
  "query": {
    "fuzzy": {
      "title": {
        "value": "auick"
      }
    }
  }
}


GET boost_index/_search
{
  "query": {
    "fuzzy": {
      "content": {
        "value": "auick"
      }
    }
  }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值