此文档基于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"
}
}
}
}