Thanks to the guys at Elasticsearch for helping me with this. The answer is to convert the JSON to a Map
and then just pass the Map
as a param:
String script = "ctx._source.pete = jsonMap";
Map<String, Object> jsonMap = new ObjectMapper().readValue(json, HashMap.class);
Map<String, Object> params = ImmutableMap.of("jsonMap", jsonMap);
return new Script(script, ScriptService.ScriptType.INLINE, null, params);
I'm using org.codehaus.jackson.map.ObjectMapper
to do the conversion from JSON to the Map
.