protected UpdateRequest nestedUpsert(String field, String key, Map<String, Object> item) {
return new UpdateRequest()
- .script("if(ctx._source.containsKey(\""+field+"\")){for (int i = 0; i < ctx._source." + field + ".size(); i++){" +
- "if(ctx._source." + field + "[i]._id == update_id){ ctx._source." + field + "[i] = update_doc; update_done = true;}}" +
- "if(!update_done){ ctx._source." + field + " += update_doc; }\n} else {ctx._source." + field + " = [update_doc];}")
+ .script("for (int i = 0; i < ctx._source." + field + ".size(); i++){" +
+ "if(ctx._source." + field + "[i]._id == update_id){"
+ + " ctx._source." + field + "[i] = update_doc; "
+ + " update_done = true;}} "
+ + "if(!update_done){ ctx._source." + field + " += update_doc; }")
.addScriptParam("update_id", key)
.addScriptParam("update_doc", item)
.addScriptParam("update_done", false);
-
}
}