# How to get the \_search\_shards informations with Java API

**URL:** <https://discuss.elastic.co/t/how-to-get-the--search-shards-informations-with-java-api/59433>\
**Category:** Elasticsearch\
**Created:** [August 31, 2016, 2:10pm UTC](https://discuss.elastic.co/t/how-to-get-the--search-shards-informations-with-java-api/59433 "2016-08-31T14:10:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gacio](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@gacio](https://discuss.elastic.co/u/gacio)\
**Post date:** [August 31, 2016, 2:10pm UTC](https://discuss.elastic.co/t/how-to-get-the--search-shards-informations-with-java-api/59433/1 "2016-08-31T14:10:40Z")

</div>

I want to get in programmatic way the data that is available through  
`/IDXNAME/TYPENAME/_search_shards?routing=route2`

Sadly this is not documented in Java API. However I have found that there is a method  
`client().admin().cluster().searchShards(clusterSearchShardsRequest)`  
with code like:

```
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 the `clusterSearchShardsRequest`initialization is incorrect here so for a given (client,index,type). How can one fix this code to give the \_search\_shard informations?

**How can I get the `_search_shards` functionality with Java API?**

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:23pm UTC](https://discuss.elastic.co/t/how-to-get-the--search-shards-informations-with-java-api/59433/2 "2017-07-05T22:23:33Z")

</div>


