[Feature] elasticsearch 如何查询一个 document 落在 index 的 哪个 shard 上?
相关组件
elasticsearch 6.7.1
解决方案
GET test/_doc/_search?q=_id:3a944c0a273cb2c95d2ba6ed5e10911e
{
"explain": true
}
输出:
# hit 里有个 _shard
{
"took" : 33,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_shard" : "[test][1]",
"_node" : "V48uxC41TRO2shnXORozcQ",
"_index" : "test",
"_type" : "_doc",
"_id" : "3a944c0a273cb2c95d2ba6ed5e10911e",
"_score" : 1.0,
"_source" : {
"content": "xxx"
},
"_explanation" : {
"value" : 1.0,
"description" : "ConstantScore(_id:[dd af 78 e1 cd 1a db bd dc 6f 67 3d e5 dd 9b 6b a7 9d e5 ed 74 f7 5d 5e])",
"details" : [ ]
}
}
]
}
}
参考文档
- Is it possible to find which elasticsearch shard(s) a document is on?
- Computing Distance from a Reference Point with Script Fields and the Explain API
遇到的问题
其实参考文档说得非常直截了当,但是我昨天依旧没解决。
最后实在是没办法了,调用下面这个 api,一个一个 shard 地试,才暴力找到的。
GET test/_doc/3a944c0a273cb2c95d2ba6ed5e10911e?preference=_shards:1
因为我虽然看了文档,但却把 explain 放错了位置,我寻思应该没啥毛病。
于是就把 explain 放参数后了,也就是
GET test/_doc/_search?q=_id:3a944c0a273cb2c95d2ba6ed5e10911e&explain
现在想来,实在是毫无依据……

浙公网安备 33010602011771号