# Bulk-update using Rest Client throws IOException

**URL:** <https://discuss.elastic.co/t/bulk-update-using-rest-client-throws-ioexception/121205>\
**Category:** Elasticsearch\
**Created:** [February 23, 2018, 11:21am UTC](https://discuss.elastic.co/t/bulk-update-using-rest-client-throws-ioexception/121205 "2018-02-23T11:21:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shobhana](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@shobhana](https://discuss.elastic.co/u/shobhana)\
**Post date:** [February 23, 2018, 11:21am UTC](https://discuss.elastic.co/t/bulk-update-using-rest-client-throws-ioexception/121205/1 "2018-02-23T11:21:50Z")

</div>

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 bulk API to index documents and it works fine. Why is update failing?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [March 2, 2018, 1:36pm UTC](https://discuss.elastic.co/t/bulk-update-using-rest-client-throws-ioexception/121205/2 "2018-03-02T13:36:08Z")

</div>

hi @shobhana ,  
I have run your bulk request and it looks ok to me.

Could you maybe share your entire code, how you create your rest client instance etc ? Were you able to isolate the problem with this specific bulk request after you ingested those two documents that you are trying to update?

Thanks  
Luca

---

<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:** [March 30, 2018, 1:36pm UTC](https://discuss.elastic.co/t/bulk-update-using-rest-client-throws-ioexception/121205/3 "2018-03-30T13:36:13Z")

</div>

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