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??