# Java API update document

**URL:** https://discuss.elastic.co/t/java-api-update-document/11160
**Category:** Elasticsearch
**Created:** [March 14, 2013, 6:22pm UTC](https://discuss.elastic.co/t/java-api-update-document/11160 "2013-03-14T18:22:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![steam](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@steam](https://discuss.elastic.co/u/steam)
#### Post date: [March 14, 2013, 6:22pm UTC](https://discuss.elastic.co/t/java-api-update-document/11160/1 "2013-03-14T18:22:35Z")

</div>

Hello,  
I need help to do update document with java api. I'm trying to build update with setScriptParams. Update fails with exception:

org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: script or doc is missing;

But with line setScript (commented setScriptParams) this works well.  
I need to execute as name - value.

Thanks.

this is my code

String newTitle = "new title value";

HashMap\<String, Object\> scriptParams = new HashMap\<String, Object\>();  
scriptParams.put("title", "new title");  
scriptParams.put("description", "new description");

response = client.prepareUpdate().setIndex(ItemConstant.INDEX\_ITEMS)  
.setType(type)  
.setId(id)   
.setScriptParams(scriptParams)  
//.setScript("ctx.\_source.title="" + newTitle + """)  
.setRetryOnConflict(5)  
.setRefresh(true)  
.execute()  
.actionGet();

---

<div class="post-metadata">

### Author: ![mubs0808](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@mubs0808](https://discuss.elastic.co/u/mubs0808)
#### Post date: [April 26, 2013, 3:11am UTC](https://discuss.elastic.co/t/java-api-update-document/11160/2 "2013-04-26T03:11:00Z")

</div>

Found the below code on this link, this might help  
[http://elasticsearch-users.115913.n3.nabble.com/Update-Api-in-java-td4021000.html](http://elasticsearch-users.115913.n3.nabble.com/Update-Api-in-java-td4021000.html)

Example showing how to update a title field:  
Node node = nodeBuilder().client(true).node();  
Client client = node.client();  
String index = "my\_index";  
String type= "my\_type";  
String id = "1";  
String newTitle = "my new title";  
client.prepareUpdate(index, type, id)  
.setScript("ctx.\_source.title="" + newTitle + """)  
.execute()  
.actionGet();

---

<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 6, 2017, 2:39am UTC](https://discuss.elastic.co/t/java-api-update-document/11160/3 "2017-07-06T02:39:33Z")

</div>


