如何从ClusterSearchShardsRequest获取所有信息

时间:2016-08-29 17:01:36

标签: elasticsearch elasticsearch-java-api

我设计了以下代码,以获取类似于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

1 个答案:

答案 0 :(得分:0)

只需使用索引名称aprameter创建new ClusterSearchShardsRequest(BOOK_INDEX_NAME)