この設定を使用して、次の1
ような URLを持つ ID を持つツイート ドキュメントの ES シャード #2 をクエリできます。
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:
このインデックスのシャードが 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
}