文章目录
explain api非常有用,一般情况下业务人员如果反馈排序为什么不是预期的样子,如果你使用了es来做排序的话,那么就需要使用它的explain功能来做深度问题排查了
这个explain会给出打分的具体原因,当然,你要稍微熟悉一下es的默认的打分算法BM25
使用
GET /twitter/_explain/0
{
"query" : {
"match" : { "message" : "elasticsearch" }
}
}
返回样例
{
"_index":"twitter",
"_type":"_doc",
"_id":"0",
"matched":true,
"explanation":{
"value":1.6943597,
"description":"weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
"details":[
{
"value":1.6943597,
"description":"score(freq=1.0), product of:",
"details":[
{
"value":2.2,
"description":"boost",
"details":[]
},
{
"value":1.3862944,
"description":"idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details":[
{
"value":1,
"description":"n, number of documents containing term",
"details":[]
},
{
"value":5,
"description":"N, total number of documents with field",
"details":[]
}
]
},
{
"value":0.5555555,
"description":"tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details":[
{
"value":1.0,
"description":"freq, occurrences of term within document",
"details":[]
},
{
"value":1.2,
"description":"k1, term saturation parameter",
"details":[]
},
{
"value":0.75,
"description":"b, length normalization parameter",
"details":[]
},
{
"value":3.0,
"description":"dl, length of field",
"details":[]
},
{
"value":5.4,
"description":"avgdl, average length of field",
"details":[]
}
]
}
]
}
]
}
}
可以带的参数
_source
设置为true以返回文档的_source。您还可以使用_source_includes和_source_excludes来检索文档的一部分(有关更多详细信息,请参见获取API)
stored_fields
返回哪些stored_fields
routing
如果在索引编制过程中使用了路由,则控制路由。
parent
与设置路由参数相同。
preference
控制对解释执行的分片。
source
允许将请求的数据放入url的查询字符串中。
q
查询字符串(映射到query_string查询)。
df
在查询中未定义任何字段前缀时使用的默认字段。
analyzer
分析查询字符串时要使用的分析器名称。默认为默认搜索分析器。
analytics_wildcard
是否应分析通配符和前缀查询。默认为false。
lenient
如果设置为true,将导致忽略基于格式的错误(例如,向数字字段提供文本)。默认为false。
default_operator
要使用的默认运算符可以是AND或OR。默认为OR。