我可以使用首选项来查询 ES shard #2 以获取带有 id 的推文文档,1
其 URL 如下所示:
GET twitter/tweet/1/_search?preference=_shards:2
如何使用 Java API 做到这一点?
编辑这个:
GET /bookshop/book/_search?preference=_shards:0
列出文档,而以下两者都返回 NPE:
GET /bookshop/book/id1?preference=_shards:0 //NPE
和
GetResponse getResponse = client()
.prepareGet(BOOK_INDEX_NAME, BOOK_TYPE_NAME, "id1")
.setPreference("_shards:0")
.execute().actionGet();
System.out.print(getResponse.getSource()); //HERE IS WHERE I GET THE NPE
编辑2:
那为什么如果我只有两个分片用于这个索引
GET /bookshop/book/id1?preference=_shards:0
我得到 NPE 和
> GET /bookshop/book/id1?preference=_shards:1
我得到“找到:假”:
{
"_index": "bookshop",
"_type": "book",
"_id": "id1",
"found": false
}
和
GET /bookshop/book/_search?preference=_shards:0
得到实际的文件id1
和完整的_source
?
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "bookshop",
"_type": "book",
"_id": "id1",
"_score": 1,
"_routing": "route1",
"_source": {
"title": "Clean COde",
"author": "John Smith"
}
}
]
}
}
EDIT3: 对于:
GET /bookshop/book/id1?preference=_shards:0
我得到以下回复
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[master-1][127.0.0.1:9304][indices:data/read/get[s]]"
}
],
"type": "null_pointer_exception",
"reason": null
},
"status": 500
}