27.四种常见的相关度分数优化方法

不想你离开。 提交于 2020-05-07 16:43:28

对相关度评分进行调节和优化的常见的4种方法

   

一、query-time boost,

如果认为某一个term的比较重要,就把这个term的权重设的大一点,也就是把boost的值设的大一点。

   

GET /forum/article/_search

{

"query": {

"bool": {

"should": [

{

"match": {

"title": {

"query": "java spark",

"boost": 2

}

}

},

{

"match": {

"content": "java spark"

}

}

]

}

}

}

   

2、重构查询结构

重构查询结构就是优化查询语句。重构查询结果,在es新版本中,影响越来越小了。一般情况下,没什么必要的话,不用也行。

   

GET /forum/article/_search

{

"query": {

"bool": {

"should": [

{

"match": {

"content": "java"

}

},

{

"match": {

"content": "spark"

}

},

{

"bool": {

"should": [

{

"match": {

"content": "solution"

}

},

{

"match": {

"content": "beginner"

}

}

]

}

}

]

}

}

}

   

三、negative boost

   

1、搜索包含java,不包含sparkdoc,这样只要包含sparkdoc都会直接排除,

2、搜索包含java,尽量不包含sparkdoc,如果包含了spark,不会直接排除掉这个doc,而只是将这个doc的分数降低。包含了negative termdoc,分数乘以negative boost,从而使这个doc的分数降低

1、搜索包含java,并且不包含sparkdoc

   

GET /forum/article/_search

{

"query": {

"bool": {

"must": [

{

"match": {

"content": "java"

}

}

],

"must_not": [

{

"match": {

"content": "spark"

}

}

]

}

}

}

2、搜索包含java,尽量不包含sparkdoc

   

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": {

"bool": {

"should": [

{

"constant_score": {

"query": {

"match": {

"title": "java"

}

}

}

},

{

"constant_score": {

"query": {

"match": {

"title": "spark"

}

}

}

}

]

}

}

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!