# addScriptParam not working in Java Update API

**URL:** https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162
**Category:** Elasticsearch
**Created:** [June 28, 2017, 5:42pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162 "2017-06-28T17:42:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)
#### Post date: [June 28, 2017, 5:42pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/1 "2017-06-28T17:42:13Z")

</div>

```
	HashMap newObject = new HashMap(); 
		newObject.put("TimeStamp", "2012-03-11T01:28:39.461Z"); 
		newObject.put("Name", "[ " +
	              "\"John1\","+
	              "\"John2\","+
	              "\"John3\""+
	              "]"); 
		
		
		UpdateRequestBuilder updater = client.prepareUpdate("index1", "type1", "1");
		updater.setScript(new Script("ctx._source.NameArray += newobject"));
		updater.addScriptParam("newobject", newObject);
		updater.execute() ;
		updater.actionGet(); 

```

where the doc is:

```
{
"NameArray" : [{
     "TimeStamp" : "2015-08-11T01:28:23.461Z",
     "Name" : ["Dan1", "Dan2"]
}]
}

```

When I try to run this, i get addScriptParam() and actionGet() is undefined.  
Which package is to be imported to make this work?

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [June 28, 2017, 9:55pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/2 "2017-06-28T21:55:25Z")

</div>

Params should be added on the Script itself. It would look something like this:

```auto
new Script(ScriptType.INLINE, "painless", "ctx._source.NameArray += params.newobject", Collections.singletonMap("newobject", newObject))

```

Also, the `actionGet()` method is on the ActionFuture returned by `execute()`, not on the builder. But you can call `get()` directly on the builder. There is no need to get the future if you want a synchronous response.

---

<div class="post-metadata">

### Author: ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)
#### Post date: [June 28, 2017, 10:23pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/3 "2017-06-28T22:23:49Z")

</div>

It doesn't work.  
Error is:  
`The constructor Script(ScriptType, String, String, Map<String,HashMap>) is undefined`

Where do I find the documentation for doing updates using scripts in Java API?  
This doc is really insufficient: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-update.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-update.html)

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [June 29, 2017, 12:32am UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/4 "2017-06-29T00:32:18Z")

</div>

Sorry, I was looking at the code for 6.0 (unreleased). The documentation you reference there is the place to look. But which constructor signature to look for depends on the version of elasticsearch you using.

---

<div class="post-metadata">

### Author: ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)
#### Post date: [June 29, 2017, 5:15pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/5 "2017-06-29T17:15:26Z")

</div>

I'm using ElasticSearch 5.4  
I found a work around.  
Thanks for all your help.

---

<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 27, 2017, 5:15pm UTC](https://discuss.elastic.co/t/addscriptparam-not-working-in-java-update-api/91162/6 "2017-07-27T17:15:34Z")

</div>

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