From 92adbad1f6c1299db4c975f26ec9d8b97f9577b7 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 23 May 2014 16:20:27 +0200 Subject: [PATCH] DAOv.2 - Simplified [] upsert for ES --- .../java/org/sonar/server/search/BaseNormalizer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java b/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java index 7a2bf15e904..d1ea10c97fb 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java @@ -77,12 +77,13 @@ public abstract class BaseNormalizer, K extends Serializable> { protected UpdateRequest nestedUpsert(String field, String key, Map 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); - } } -- 2.39.5