0

I am trying to bulk update few fields in my documents using Rest Client. Here is how my code looks like :

String updateLastUsedTimeInBulkPath = "/_bulk"; // Tried with just "_bulk" also
StringEntity updateLastUsedTimeRequest = new StringEntity(jsonStringToUpdateLastUsedTimeInBulk);
updateLastUsedTimeRequest.setContentType("application/x-ndjson");
elasticServerRestClient.performRequest("POST", updateLastUsedTimeInBulkPath, Collections.<String, String>emptyMap(), updateLastUsedTimeRequest);

jsonStringToUpdateLastUsedTimeInBulk in the above code looks like the following :

{ "update" : {"_index" : "routematch", "_type" : "routematch", "_id" : "2686101,8264892"} }
{ "doc" : {"lastUsedTime" : "1519221900208"} }
{ "update" : {"_index" : "routematch", "_type" : "routematch", "_id" : "2686101,2686101"} }
{ "doc" : {"lastUsedTime" : "1519221900209"} }

I tried to execute the same using Kibana and it worked fine and updated the fields, but it always fails when executed using RestClient with java.io.IOException: An existing connection was forcibly closed by the remote host

What is wrong with my code? I have tried the same way to index documents in bulk and it works fine with RestClient also. Why is update failing?

Shobhana Sriram
  • 394
  • 1
  • 2
  • 14
  • "it always fails when executed using RestClient" vs "it works fine with RestClient also", can you fix? – Val Feb 22 '18 at 13:53
  • Hi Val, I meant bulk-indexing works fine but bulk update fails – Shobhana Sriram Feb 23 '18 at 04:02
  • Can you try with `HttpEntity entity = new NStringEntity(jsonStringToUpdateLastUsedTimeInBulk, ContentType.APPLICATION_JSON);` instead of using `StringEntity` ? – Val Feb 23 '18 at 05:21
  • I tried this, but it made no difference .. same IOException! – Shobhana Sriram Feb 23 '18 at 09:07
  • Do all the ids exist? I was getting "An existing connection was forcibly closed by the remote host" when using the bulk API and it went away when using upserts. – Chase Jan 21 '21 at 21:45

0 Answers0