1. 开启打分说明(Explain)
在搜索时,可以开启评分说明"explain": true
,请求响应中每个命中的文档会额外返回一个得分说明字段_explanation
,如:
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"explain": true,
"query" : {
"term" : {
"content" : "中国" }
}
}
'
返回的结果为:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.111892,
"hits": [
{
"_shard": "[index][2]",
"_node": "bKeGC-Q-SXuyyGlcarDrMg",
"_index": "index",
"_type": "fulltext",
"_id": "4",
"_score": 1.111892,
"_source": {
"content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
},
// 返回得分说明
"_explanation": {
"value": 1.111892,
"description": "weight(content:中国 in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 1.111892,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 0.98082924,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 1,
"description": "docFreq",
"details": []
},
{
"value": 3,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.1336244,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 19.666666,
"description": "avgFieldLength",
"details": []
},
{
"value": 14,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
},
// ...
]
}
}
2. 开启版本说明(Version)
就是在搜索时,配置"version": true
,指定命中结果中也返回文档版本号,如下:
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"version": true,
"query": {
"term": {
"content": "中国"}
}
}
'
返回的结果会带有命中结果的版本号version
,如下:
{
"took": 0,
"timed_out": false,