Update Request from REST to JAVA API

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.
For more options, visit https://groups.google.com/groups/opt_out.

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.
For more options, visit https://groups.google.com/groups/opt_out.