ElasticSearch 有一个解释 API,它可以解释它如何在内部对具有特定 id 的特定记录的字段命中进行评分。
这是文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
它肯定会为您提供有关如何提升每个字段以及如何建立分数的答案。
例如,如果您的 hits max_score 为 2.0588222,并且您想知道哪些字段对该分数的贡献,您可以使用 explain API。
这是一个解释查询响应的示例,您可以看到字段 firstName 贡献了 1.2321436 到最高得分,而 lastName 贡献了 0.8266786:
{
"_index" : "customer_test",
"_type" : "customer",
"_id" : "597f2b3a79c404fafefcd46e",
"matched" : true,
"explanation" : {
"value" : **2.0588222**,
"description" : "sum of:",
"details" : [ {
"value" : 2.0588222,
"description" : "sum of:",
"details" : [ {
"value" : **1.2321436**,
"description" : "weight(firstName:merge in 23) [PerFieldSimilarity], result of:",
"details" : [ {
"value" : 1.2321436,
"description" : "score(doc=23,freq=1.0 = termFreq=1.0\n), product of:",
"details" : [ {
"value" : 1.2321436,
"description" : "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details" : [ {
"value" : 3.0,
"description" : "docFreq",
"details" : [ ]
}, {
"value" : 11.0,
"description" : "docCount",
"details" : [ ]
} ]
}, {
"value" : 1.0,
"description" : "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details" : [ {
"value" : 1.0,
"description" : "termFreq=1.0",
"details" : [ ]
}, {
"value" : 1.2,
"description" : "parameter k1",
"details" : [ ]
}, {
"value" : 0.75,
"description" : "parameter b",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "avgFieldLength",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "fieldLength",
"details" : [ ]
} ]
} ]
} ]
}, {
"value" : 0.8266786,
"description" : "weight(lastName:doe in 23) [PerFieldSimilarity], result of:",
"details" : [ {
"value" : 0.8266786,
"description" : "score(doc=23,freq=1.0 = termFreq=1.0\n), product of:",
"details" : [ {
"value" : **0.8266786**,
"description" : "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details" : [ {
"value" : 3.0,
"description" : "docFreq",
"details" : [ ]
}, {
"value" : 7.0,
"description" : "docCount",
"details" : [ ]
} ]
}, {
"value" : 1.0,
"description" : "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details" : [ {
"value" : 1.0,
"description" : "termFreq=1.0",
"details" : [ ]
}, {
"value" : 1.2,
"description" : "parameter k1",
"details" : [ ]
}, {
"value" : 0.75,
"description" : "parameter b",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "avgFieldLength",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "fieldLength",
"details" : [ ]
} ]
} ]
} ]
} ]
}, {
"value" : 0.0,
"description" : "match on required clause, product of:",
"details" : [ {
"value" : 0.0,
"description" : "# clause",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "_type:customer, product of:",
"details" : [ {
"value" : 1.0,
"description" : "boost",
"details" : [ ]
}, {
"value" : 1.0,
"description" : "queryNorm",
"details" : [ ]
} ]
} ]
} ]
}
}
关于鹡鸰:我没有这方面的经验。但您绝对可以访问 REST API 并解析 Explain 查询的 JSON。