我正在搜索按" sortScore"排序的文档列表。
查询:
GET /myindex/_search
{
"from": 0,
"size": 1000,
"sort": [
{
"sortScore":{"order":"desc"}
}
]
}
示例输出:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"failed": 0
},
"hits": {
"total": 41619,
"max_score": null,
"hits": [
{
"_index": "myindex",
"_type": "stock",
"_id": "D1393201",
"sortScore":"1.7972717285156"
},
"sort": [
1.7972717285156
]
},
{
"_index": "myindex",
"_type": "stock",
"_id": "D1421470",
"sortScore":"1.7966537475586"
},
"sort": [
1.7966537475586
]
},
{
"_index": "myindex",
"_type": "stock",
"_id": "D1418136",
"sortScore":"2.796630859375"
},
"sort": [
2.796630859375
]
}
]
}
}
现在按上述顺序搜索特定文档,我可以这样做。
查询:
GET /myindex/_search
{
"from": 0,
"size": 1000,
"sort": [
{
"sortScore":{"order":"desc"}
}
],
"query": {
"bool": {
"must": [
{
"terms": {
"_id": ["D1421470"]
}
}
]
}
}
}
这将输出给定ID的特定文档。
有什么方法可以检索此特定文档的排名(按排序命中)?上述查询应为2
。
答案 0 :(得分:0)
默认情况下,Elasticsearch使用其内部"排名算法"对结果进行排序。或者某个时候也被称为" Relevance"并且结果是基于相关性得分的顺序。
"_score": 4.6314874
一个简单的例子就是,当你搜索术语" Apple",并且这些文件有" Apple"在该领域的某个地方,然后相关性决定了事实,例如"这个术语重复的次数和#34; (即术语频率),整个值的长度/大小,索引中的总术语频率等。
Doc1:" Cat"
Doc2:" Apple和Ball"
Doc3:" Apple"
Doc4:" Apple ball and cat"
{
"query": {
"query_string": {
"query": "Apple"
}
}
}
订单或结果文档将是:Doc3(完全匹配),Doc2(匹配和长度很小)和Doc4。