我设计了以下代码,以获取类似于ES中的_search_shards
rest API的信息:
ClusterSearchShardsRequest clusterSearchShardsRequest
= new ClusterSearchShardsRequest();
clusterSearchShardsRequest.routing("route2");
try {
DiscoveryNode[] discoveryNodes = client().admin().cluster()
.searchShards(clusterSearchShardsRequest)
.get()
.getNodes();
for (int i=0; i<=discoveryNodes.length; i++){
System.out.print("\n\n\n"+discoveryNodes[i].toString()+"\n\n\n");
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
然而,这往往不会初始化实际的clusterSearchShardsRequest
。
如何初始化给定clusterSearchShardsRequest
和索引的client
?
答案 0 :(得分:0)
只需使用索引名称aprameter创建new ClusterSearchShardsRequest(BOOK_INDEX_NAME)
。