搜索的相关性算分

####################搜索的相关性算分##################

搜索的相关性—relevance

搜索的相关性算分,描述了一个文档和查询语句匹配的程度,es会对每个匹配查询条件的结果进行算分_score

打分的本质就是排序。把最符合用户需求的文档排在前面,es5之前。默认的相关性算分采用TF-IDF,现在采用BM25

词频TF

term Frequency 英 /ˈfriːkwənsi/ : 检索词在一篇文档中出现的频率 检索词出现的次数除以文档的总字数

度量一条查询和结果相关性的简单方法:简单将搜索中的每一个词的TF 进行相加

逆文档频率 IDF

###DF:检索词在所有文档词中出现的频率

inverse document frequency 简单说= log(全部文档数/检索词出现过的文档总数) TF-IDF 本质上就是将TF求和变成了加权求和

PUT testscore
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text"
      }
    }
  }
}


PUT testscore/_bulk
{ "index": { "_id": 1 }}
{ "content":"we use Elasticsearch to power the search" }
{ "index": { "_id": 2 }}
{ "content":"we like elasticsearch" }
{ "index": { "_id": 3 }}
{ "content":"The scoring of documents is caculated by the scoring formula" }
{ "index": { "_id": 4 }}
{ "content":"you know, for search" }

### 通过explain 查看es计算得分的过程
POST testscore/_search
{
  "explain": true,
  "query": {
    "match": {
      //"content":"you"
      //"content": "elasticsearch"
      //"content":"the"
      "content": "the elasticsearch"
    }
  }
}

可以通过boosting 进行设置词的权重,来影响得分的结果,例如,通过positive来设置包含哪些词会提高得分,通过negative来设置如果怎么样会降低得分,参数 boost的含义

#● 当 boost > 1 时,打分的相关度相对性提升
#● 当 0 < boost < 1 时,打分的权重相对性降低
#复合查询:Boosting Query
#● 当 boost < 0 时,贡献负分

POST testscore/_search
{
  "query": {
    "boosting": {
      "positive": {
        "term": {
          "content": {
            "value": "elasticsearch"
          }
        }
      },
      "negative": {
        "term": {
          "content": {
            "value": "like"
          }
        }
      },
      "negative_boost": 0.2
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值