# Update API in Java Rest Client not updating document in ElasticSearch

**URL:** <https://discuss.elastic.co/t/update-api-in-java-rest-client-not-updating-document-in-elasticsearch/153450>\
**Category:** Elasticsearch\
**Created:** [October 22, 2018, 5:07pm UTC](https://discuss.elastic.co/t/update-api-in-java-rest-client-not-updating-document-in-elasticsearch/153450 "2018-10-22T17:07:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shweta\_Sinha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shweta_sinha/32/72128_2.png) [@Shweta\_Sinha](https://discuss.elastic.co/u/Shweta_Sinha)\
**Post date:** [October 22, 2018, 5:07pm UTC](https://discuss.elastic.co/t/update-api-in-java-rest-client-not-updating-document-in-elasticsearch/153450/1 "2018-10-22T17:07:08Z")

</div>

RestHighLevelClient client = new RestHighLevelClient(  
RestClient.builder(  
new HttpHost("localhost", 9200, "http"));  
String json = mapper.writeValueAsString(new DensityVersion(new Date(), 300L));  
Map\<String, Object\> param = new HashMap\<\>();  
param.put("hits", json);  
Script script= new Script(ScriptType.INLINE, "painless",  
""ctx.\_source.density.add(params.hits)"", param);  
UpdateRequest updateRequest = new UpdateRequest("mortontile", "tile", "6bce965").script(script);  
client.update(updateRequest, RequestOptions.DEFAULT);

I need to add my new document in an array.  
Response.getResult is Updated and version is also updated by 1, everytime I run my update request.  
But When I fetch the same data , its not updated.

Post query is working fine.

POST mortontile/tile/\_update\_by\_query?pretty  
{  
"script": {  
"inline": "ctx.\_source.density.add(params.hits)",  
"params": {"hits": {  
"timestamp": 1539159342939,  
"density": 100  
}}  
},  
"query": {  
"match": {"tileId":"6bce965"}  
}  
}

Any help would be appreciated.  
Thanks

---

<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:** [November 19, 2018, 5:07pm UTC](https://discuss.elastic.co/t/update-api-in-java-rest-client-not-updating-document-in-elasticsearch/153450/2 "2018-11-19T17:07:09Z")

</div>

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