1. 程式人生 > >27.四種常見的相關度分數優化方法

27.四種常見的相關度分數優化方法

什麽 OS -c ould ack 四種 AC 查詢語句 spark

對相關度評分進行調節和優化的常見的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"

}

}

}

}

]

}

}

}

27.四種常見的相關度分數優化方法