# Java High level Rest Client(5.6), getting succesful shard info count

**URL:** <https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045>\
**Category:** Elasticsearch\
**Created:** [May 31, 2018, 12:32pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045 "2018-05-31T12:32:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neha\_goswami](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@Neha\_goswami](https://discuss.elastic.co/u/Neha_goswami)\
**Post date:** [May 31, 2018, 12:32pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/1 "2018-05-31T12:32:39Z")

</div>

Hi i am working on migration from Transport client to restClient:

M stuck here:

using transport client this was done as:

XContentBuilder builder = jsonBuilder().startObject().field("ProcessName", processName).field(StrConstants.Status, status).endObject();

IndexRequest indexRequest = new IndexRequest(index, type).id(this.statId).source(builder);  
UpdateResponse resp = this.client.update(new UpdateRequest(index, type,id).doc(builder).upsert(indexRequest)).actionGet(TimeValue.timeValueSeconds(this.timeoutSecs));

& now using RestClient we can do it AS:  
HttpEntity entity = new NStringEntity(  
"{\n" +  
" "ProcessName" : ""+processName+"",\n" +  
" "Status" : ""+status+"",\n" +  
" "StatLastModified" : ""+new Date()+""\n" +  
"}", ContentType.APPLICATION\_JSON);

```
			ResponseListener responseListener = new ResponseListener() {
			    @Override
			    public void onSuccess(Response response){
			    	try {
						logger.info(" Written Status to ES >>> " + EntityUtils.toString(response.getEntity()));
					} catch (ParseException | IOException e) {
						logger.error("Exception occurred "+e);
					}
			    }

			    @Override
			    public void onFailure(Exception exception) {
			    	logger.info(" NOT Written to ES...."+exception);
			    }
			};

			Map<String, String> params = Collections.emptyMap();
			restClient.performRequestAsync("PUT", getEndPoint(index, type, id), params, entity, responseListener);

```

Now after this in code. we had a retry logic which needed the succesful shard info :  
int success = resp.getShardInfo().getSuccessful(); ------\> Now to do this using RestClient Response  
In rest client response we only get json response using :

EntityUtils.toString(response.getEntity())

How can i get the succesful shard info count here??

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 31, 2018, 12:47pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/2 "2018-05-31T12:47:03Z")

</div>

> [@Neha\_goswami](#):
>
> Response

This can help you...

> **[Index API | Java REST Client \[5.6\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/java-rest-high-document-index.html)**

---

<div class="post-metadata">

**Author:** ![Neha\_goswami](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@Neha\_goswami](https://discuss.elastic.co/u/Neha_goswami)\
**Post date:** [June 1, 2018, 5:23am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/3 "2018-06-01T05:23:52Z")

</div>

I had gone through this link, confusioin here is that link says to get output from IndexResponse like below:

Synchronous Execution

IndexResponse indexResponse = client.index(request);

But, indexResponse is fetched using client object...this is not restClient Object right??

When we are migrating to restClient, we should move everything to restClient right???

From restClient way of getting index response is : :  
Response response= restClient.performRequestAsync("PUT", getEndPoint(index, type, id), params, entity, responseListener);

Now from this response i am not able to fetch successful shard info:

Pls guide me if im on right direction

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [June 1, 2018, 2:00pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/4 "2018-06-01T14:00:04Z")

</div>

```auto
      @Override
      public void onResponse(IndexResponse indexResponse) {
        // This is where you can get the Shard Infos
       ReplicationResponse.ShardInfo shardInfo = indexResponse.getShardInfo();
        System.out.println(shardInfo.getSuccessful());
      }

      @Override
      public void onFailure(Exception e) {

      }
    };

```

---

<div class="post-metadata">

**Author:** ![Neha\_goswami](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@Neha\_goswami](https://discuss.elastic.co/u/Neha_goswami)\
**Post date:** [June 5, 2018, 2:26am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/5 "2018-06-05T02:26:42Z")

</div>

> [@Neha\_goswami](#):
>
> u

Thanks.

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [June 5, 2018, 3:44pm UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/6 "2018-06-05T15:44:16Z")

</div>

@Neha_goswami did it solve the problem?? if yes please mark it as solution.

---

<div class="post-metadata">

**Author:** ![Neha\_goswami](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@Neha\_goswami](https://discuss.elastic.co/u/Neha_goswami)\
**Post date:** [June 6, 2018, 9:14am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/7 "2018-06-06T09:14:27Z")

</div>

Yes actually i was not getting the correct high level rest client instance.  
Updating correct dependency in pom.xml solved my problem

---

<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 4, 2018, 9:14am UTC](https://discuss.elastic.co/t/java-high-level-rest-client-5-6-getting-succesful-shard-info-count/134045/8 "2018-07-04T09:14:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
