ElasticSearch具有Explain API,它可以解釋如何使用特定ID爲特定記錄按內容對字段進行內部打分。
下面是文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
它絕對讓你在每場是如何提振和分數是如何構建一個答案。
例如,如果您的匹配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。
這聽起來很棒@ gil.fernandes - 但我不知道如何使用這個特性使用內置的_wagtail作爲後端搜索的elasticsearch,如果有人能指點我的示例實現 – tombreit