Search code examples
elasticsearchelasticsearch-java-api

How to get all the info from ClusterSearchShardsRequest


I have devised the following code to get the info similar to _search_shards rest API in ES:

    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();
                }

However this tends not to initialize the actual clusterSearchShardsRequest.

How to initialize the clusterSearchShardsRequest for the given client and index?


Solution

  • Simply create the new ClusterSearchShardsRequest(BOOK_INDEX_NAME) with the index name aprameter.