]> source.dussan.org Git - sonarqube.git/commitdiff
DAOv.2 - Simplified [] upsert for ES
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 23 May 2014 14:20:27 +0000 (16:20 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 23 May 2014 15:39:03 +0000 (17:39 +0200)
sonar-server/src/main/java/org/sonar/server/search/BaseNormalizer.java

index 7a2bf15e9049355fa12c0bdfa249d4b6ba12be27..d1ea10c97fb2f0671fc0c80786df66a9d10187d4 100644 (file)
@@ -77,12 +77,13 @@ public abstract class BaseNormalizer<E extends Dto<K>, K extends Serializable> {
 
   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);
-
   }
 }