我遇到弹性搜索问题2.2:
我有以下搜索查询:
{
"query": {
"indices": {
"index": "my_index",
"query": {
"dis_max": {
"tie_breaker": 0,
"boost": 2,
"queries": [
{
"function_score": {
"query": {
"query_string": {
"fields": [
"searchName"
],
"query": "\"sala\"",
"use_dis_max": false,
"boost": 10
}
},
"field_value_factor": {
"field": "rank",
"factor": 11,
"modifier": "log1p"
},
"boost_mode": "sum",
"boost": 20
}
}
]
}
},
"no_match_query": "none"
}
},
"size": 1
}
在Elasticsearch 2.1上运行查询,"解释"返回以下结果:
{
"took":16,
"timed_out":false,
"_shards":{
"total":21,
"successful":21,
"failed":0
},
"hits":{
"total":19,
"max_score":227.97464,
"hits":[
{
"_source":{
"rank":0,
"searchName":"Puma evoSPEED Sala 3.4"
},
"_explanation":{
"value":227.97464,
"description":"function score, product of:",
"details":[
{
"value":5.699366,
"description":"sum of",
"details":[
{
"value":5.699366,
"description":"weight(searchName:sala^10.0 in 29236) [PerFieldSimilarity], result of:",
"details":[
{
"value":5.699366,
"description":"fieldWeight in 29236, product of:",
"details":[
{
"value":1,
"description":"tf(freq=1.0), with freq of:",
"details":[
{
"value":1,
"description":"termFreq=1.0",
"details":[
]
}
]
},
{
"value":11.398732,
"description":"idf(docFreq=3, maxDocs=131272)",
"details":[
]
},
{
"value":0.5,
"description":"fieldNorm(doc=29236)",
"details":[
]
}
]
}
]
},
{
"value":0,
"description":"min of:",
"details":[
{
"value":0,
"description":"field value function: log1p(doc['rank'].value * factor=11.0)",
"details":[
]
},
{
"value":3.4028235e+38,
"description":"maxBoost",
"details":[
]
}
]
}
]
},
{
"value":40,
"description":"queryBoost",
"details":[
]
}
]
}
}
]
}
}
在Elasticsearch 2.2上,"解释"返回以下结果:
{
"took":15,
"timed_out":false,
"_shards":{
"total":21,
"successful":21,
"failed":0
},
"hits":{
"total":19,
"max_score":5.743438,
"hits":[
{
"_source":{
"rank":0,
"searchName":"Puma evoSPEED Sala 3.4"
},
"_explanation":{
"value":5.743438,
"description":"sum of",
"details":[
{
"value":5.743438,
"description":"weight(searchName:sala in 88079) [PerFieldSimilarity], result of:",
"details":[
{
"value":5.743438,
"description":"fieldWeight in 88079, product of:",
"details":[
{
"value":1,
"description":"tf(freq=1.0), with freq of:",
"details":[
{
"value":1,
"description":"termFreq=1.0",
"details":[
]
}
]
},
{
"value":11.486876,
"description":"idf(docFreq=3, maxDocs=143368)",
"details":[
]
},
{
"value":0.5,
"description":"fieldNorm(doc=88079)",
"details":[
]
}
]
}
]
},
{
"value":0,
"description":"min of:",
"details":[
{
"value":0,
"description":"field value function: log1p(doc['rank'].value * factor=11.0)",
"details":[
]
},
{
"value":3.4028235e+38,
"description":"maxBoost",
"details":[
]
}
]
}
]
}
}
]
}
}
如您所见,在两种情况下,因子使用的字段均为0,但在ES2.1中,文档的分数为227.97464(这是正确的),而在ES2.2中则为5.743438。
在ES2.1中,最外面的计算包含一个"函数得分,产品:"增强(40 = 20 * 2),计算得分为5.699366。
在ES2.2中,缺少此步骤,因此结果仅为5.743438。 5.699366到5.743438的小差异可能没问题,因为索引中的文档数量略有不同。 但是,在ES2.2中,显然仍应考虑提升。
现在我的问题是:我做错了什么(如果是的话:什么?)或者在Elasticsearch 2.2中计算得分真的有错误吗?