# Update Request from REST to JAVA API

**URL:** https://discuss.elastic.co/t/update-request-from-rest-to-java-api/12824
**Category:** Elasticsearch
**Created:** [July 17, 2013, 12:35pm UTC](https://discuss.elastic.co/t/update-request-from-rest-to-java-api/12824 "2013-07-17T12:35:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alexander\_Eder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_eder/32/2228_2.png) [@Alexander\_Eder](https://discuss.elastic.co/u/Alexander_Eder)
#### Post date: [July 17, 2013, 12:35pm UTC](https://discuss.elastic.co/t/update-request-from-rest-to-java-api/12824/1 "2013-07-17T12:35:23Z")

</div>

Hallo,  
I'm trying to convert a working REST Update Request to a similar JAVA call.

{  
"script" :  
"ctx.\_source.service.serviceUnits[index].allotments.remove(oldAllotment);  
ctx.\_source.service.serviceUnits[index].allotments += newAllotment",  
"params" : {  
"index": 0,  
"oldAllotment" :  
{"reference":"---","date":"2013-01-01","amount":12,"requestAllowed":false,"salesChannel":"-","releaseDate":"2013-12-31"},  
"newAllotment" :  
{"reference":"---","date":"2013-01-01","amount":0,"requestAllowed":true,"salesChannel":"-","releaseDate":"2013-12-31"}  
}  
}

private static final String MERGEALLOTMENT =  
"ctx.\_source.service.serviceUnits[index].allotments.remove(oldAllotment);ctx.\_source.service.serviceUnits[index].allotments  
+= newAllotment";

Map\<String, Object\> params = new HashMap\<String, Object\>();  
params.put("index", index);  
params.put("oldAllotment", oldAllotment);  
params.put("newAllotment", newAllotment);  
UpdateResponse actionGet = client.prepareUpdate("catalyst", hit.getType(),  
hit.getId())  
.setScript(MERGEALLOTMENT)  
.setScriptParams(params)  
.execute()  
.actionGet();

I have allready tried several combinations like:  
Map\<String, Object\> params = new HashMap\<String, Object\>();  
params.put("index", index);  
params.put("oldAllotment", mapper.writeValueAsString(oldAllotment));  
params.put("newAllotment", mapper.writeValueAsString(newAllotment));

but haven't found any working solution.

can anybody help me on how to set the params map right.  
-Alex

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Alexander\_Eder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_eder/32/2228_2.png) [@Alexander\_Eder](https://discuss.elastic.co/u/Alexander_Eder)
#### Post date: [July 17, 2013, 12:57pm UTC](https://discuss.elastic.co/t/update-request-from-rest-to-java-api/12824/2 "2013-07-17T12:57:11Z")

</div>

got it working  
Map\<String, Object\> params = new HashMap\<String, Object\>();  
params.put("index", index);  
params.put("oldAllotment", mapper.convertValue(oldAllotment, Map.class));  
params.put("newAllotment", mapper.convertValue(newAllotment, Map.class));

Am Mittwoch, 17. Juli 2013 14:35:23 UTC+2 schrieb Alexander Eder:

> Hallo,  
> I'm trying to convert a working REST Update Request to a similar JAVA call.
> 
> {  
> "script" :  
> "ctx.\_source.service.serviceUnits[index].allotments.remove(oldAllotment);  
> ctx.\_source.service.serviceUnits[index].allotments += newAllotment",  
> "params" : {  
> "index": 0,  
> "oldAllotment" :  
> {"reference":"---","date":"2013-01-01","amount":12,"requestAllowed":false,"salesChannel":"-","releaseDate":"2013-12-31"},  
> "newAllotment" :  
> {"reference":"---","date":"2013-01-01","amount":0,"requestAllowed":true,"salesChannel":"-","releaseDate":"2013-12-31"}  
> }  
> }
> 
> private static final String MERGEALLOTMENT =  
> "ctx.\_source.service.serviceUnits[index].allotments.remove(oldAllotment);ctx.\_source.service.serviceUnits[index].allotments  
> += newAllotment";
> 
> Map\<String, Object\> params = new HashMap\<String, Object\>();  
> params.put("index", index);  
> params.put("oldAllotment", oldAllotment);  
> params.put("newAllotment", newAllotment);  
> UpdateResponse actionGet = client.prepareUpdate("catalyst", hit.getType(),  
> hit.getId())  
> .setScript(MERGEALLOTMENT)  
> .setScriptParams(params)  
> .execute()  
> .actionGet();
> 
> I have allready tried several combinations like:  
> Map\<String, Object\> params = new HashMap\<String, Object\>();  
> params.put("index", index);  
> params.put("oldAllotment", mapper.writeValueAsString(oldAllotment));  
> params.put("newAllotment", mapper.writeValueAsString(newAllotment));
> 
> but haven't found any working solution.
> 
> can anybody help me on how to set the params map right.  
> -Alex

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:25am UTC](https://discuss.elastic.co/t/update-request-from-rest-to-java-api/12824/3 "2017-07-06T02:25:57Z")

</div>


