Hi at all!
I have documents with following structure
{ "field1" : "value1",
"field2" : "value2",
"field3" : [
{
"ff1" : "vv1",
"ff2" : "vv2"
},
{
"dd1" : "v1",
"dd2" : "v2"
}
]
}
How can I append a new item in field3 array using Java API?
I've tried with XContentBuilder and with inline scripting but I receive a serialization error:
Map<String,String> newObject = new HashMap<String,String>();
newObject.put("dd3", "v3");
newObject.put("dd4", "v4");
String script = "ctx._source.types += newobject";
Map<String, Object> params = ImmutableMap.of("newObject", (Object)newObject);
client.prepareUpdate("prova_index", "event", "1").
setScript(new Script(script, ScriptType.INLINE, null, params)).execute().actionGet();
Caused by: ScriptException[failed to run inline script [ctx._source.types += newobject] using lang [groovy]]; nested: NotSerializableExceptionWrapper[missing_property_exception: No such property: newobject for class: 72749a629170e2c3c1a7aa938eda0c6ea8ccd8db]