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

对相关度评分进行调节和优化的常见的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"

}

}

}

}

]

}

}

}

posted @ 2018-03-08 16:14  outback123  阅读(441)  评论(0编辑  收藏  举报