You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2022/07/12 08:59:01 UTC

[unomi] branch UNOMI-603-migration-profiles updated (b2932f2ca -> 9e6c7a83c)

This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a change to branch UNOMI-603-migration-profiles
in repository https://gitbox.apache.org/repos/asf/unomi.git


 discard b2932f2ca UNOMI-603 : create migration for profile and fix issues
    omit 5279bd3c0 UNOMI-606 : create migration for scoring and fix issues
     add ae7afc419 UNOMI-606 : create migration for scoring and fix issues (#460)
     new 9e6c7a83c UNOMI-603 : create migration for profile and fix issues

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b2932f2ca)
            \
             N -- N -- N   refs/heads/UNOMI-603-migration-profiles (9e6c7a83c)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/unomi/shell/migration/actions/Migrate.java    |  2 +-
 .../apache/unomi/shell/migration/utils/MigrationUtils.java   | 12 ++++++------
 .../cxs/migration/migrate-2.0.0-01-segmentReindex.groovy     |  2 +-
 .../cxs/migration/migrate-2.0.0-02-scoringPlanReindex.groovy |  2 +-
 .../cxs/migration/migrate-2.0.0-03-profileReindex.groovy     |  2 +-
 .../resources/requestBody/2.0.0/base_reindex_request.json    |  4 ++--
 .../requestBody/2.0.0/update_profile_interests.json          |  4 ++++
 7 files changed, 16 insertions(+), 12 deletions(-)
 create mode 100644 tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json


[unomi] 01/01: UNOMI-603 : create migration for profile and fix issues

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a commit to branch UNOMI-603-migration-profiles
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 9e6c7a83c7750bc60d9743013c28a0af37b61126
Author: jsinovassin <js...@jahia.com>
AuthorDate: Mon Jul 11 15:54:55 2022 +0200

    UNOMI-603 : create migration for profile and fix issues
---
 .../unomi/shell/migration/impl/MigrationTo200.java |  3 +-
 .../shell/migration/utils/MigrationUtils.java      | 11 ++--
 .../migrate-2.0.0-01-segmentReindex.groovy         |  2 +-
 .../migrate-2.0.0-02-scoringPlanReindex.groovy     |  2 +-
 ...oovy => migrate-2.0.0-03-profileReindex.groovy} |  6 +-
 .../requestBody/2.0.0/base_reindex_request.json    |  4 +-
 .../resources/requestBody/2.0.0/profile_index.json | 76 ++++++++++++++++++++++
 .../2.0.0/update_profile_interests.json            |  4 ++
 8 files changed, 95 insertions(+), 13 deletions(-)

diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
index 6b94e16b7..edd92562e 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java
@@ -243,7 +243,8 @@ public class MigrationTo200 implements Migration {
 
             while (true) {
                 JSONObject responseAsJson = getResponseAsJSON(response);
-                String scrollId = responseAsJson.getString("_scroll_id");
+
+                String scrollId = responseAsJson.has("_scroll_id") ? responseAsJson.getString("_scroll_id"): null;
                 JSONArray hits = getProfileHits(responseAsJson);
 
                 if (hits.length() == 0) {
diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
index 6b93dd0a0..809e8dbc8 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
@@ -17,11 +17,10 @@
 package org.apache.unomi.shell.migration.utils;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.json.JSONObject;
 import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -32,7 +31,6 @@ import java.nio.charset.StandardCharsets;
  * @author dgaillard
  */
 public class MigrationUtils {
-    private static final Logger logger = LoggerFactory.getLogger(MigrationUtils.class);
 
     public static JSONObject queryWithScroll(CloseableHttpClient httpClient, String url) throws IOException {
         url += "?scroll=1m";
@@ -59,7 +57,8 @@ public class MigrationUtils {
         }
     }
 
-    public static void reIndex(CloseableHttpClient httpClient, BundleContext bundleContext, String esAddress, String indexName, String newIndexSettings) throws IOException {
+    public static void reIndex(CloseableHttpClient httpClient, BundleContext bundleContext, String esAddress, String indexName,
+            String newIndexSettings, String painlessScript) throws IOException {
         String indexNameCloned = indexName + "-cloned";
 
         // Init requests
@@ -71,7 +70,9 @@ public class MigrationUtils {
                 .replace("#mappingTotalFieldsLimit", originalIndexSettings.getJSONObject(indexName).getJSONObject("settings").getJSONObject("index").getJSONObject("mapping").getJSONObject("total_fields").getString("limit"));
         String reIndexRequest = resourceAsString(bundleContext, "requestBody/2.0.0/base_reindex_request.json")
                 .replace("#source", indexNameCloned)
-                .replace("#dest", indexName);
+                .replace("#dest", indexName)
+                .replace("#painless", StringUtils.isNotEmpty(painlessScript)? ", \"script\":" + painlessScript: "");
+
         String setIndexReadOnlyRequest = resourceAsString(bundleContext, "requestBody/2.0.0/base_set_index_readonly_request.json");
 
         // Set original index as readOnly
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy
index 01a2be0c6..96048e37f 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy
@@ -19,4 +19,4 @@ import org.apache.unomi.shell.migration.utils.MigrationUtils
 
 String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/segment_index.json");
 MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-segment",
-        newIndexSettings)
+        newIndexSettings, null)
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scoringPlanReindex.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scoringPlanReindex.groovy
index f30f2ae6f..46e898117 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scoringPlanReindex.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-02-scoringPlanReindex.groovy
@@ -19,4 +19,4 @@ import org.apache.unomi.shell.migration.utils.MigrationUtils
 
 String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/scoring_index.json");
 MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-scoring",
-        newIndexSettings)
+        newIndexSettings, null)
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
similarity index 80%
copy from tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy
copy to tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
index 01a2be0c6..44f2731f1 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-01-segmentReindex.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
@@ -17,6 +17,6 @@ import org.apache.unomi.shell.migration.utils.MigrationUtils
  * limitations under the License.
  */
 
-String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/segment_index.json");
-MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-segment",
-        newIndexSettings)
+String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/profile_index.json");
+MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-profile",
+        newIndexSettings, MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/update_profile_interests.json"))
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/base_reindex_request.json b/tools/shell-commands/src/main/resources/requestBody/2.0.0/base_reindex_request.json
index bf7406131..589e71084 100644
--- a/tools/shell-commands/src/main/resources/requestBody/2.0.0/base_reindex_request.json
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/base_reindex_request.json
@@ -4,5 +4,5 @@
   },
   "dest": {
     "index": "#dest"
-  }
-}
\ No newline at end of file
+  }#painless
+}
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/profile_index.json b/tools/shell-commands/src/main/resources/requestBody/2.0.0/profile_index.json
new file mode 100644
index 000000000..0808aa03e
--- /dev/null
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/profile_index.json
@@ -0,0 +1,76 @@
+{
+    "settings": {
+        "index": {
+            "number_of_shards": #numberOfShards,
+            "number_of_replicas": #numberOfReplicas,
+            "mapping.total_fields.limit": #mappingTotalFieldsLimit,
+            "max_docvalue_fields_search": #maxDocValueFieldsSearch
+        },
+        "analysis": {
+            "analyzer": {
+                "folding": {
+                    "type": "custom",
+                    "tokenizer": "keyword",
+                    "filter": [
+                        "lowercase",
+                        "asciifolding"
+                    ]
+                }
+            }
+        }
+    },
+    "mappings": {
+        "dynamic_templates": [
+            {
+                "all": {
+                    "match": "*",
+                    "match_mapping_type": "string",
+                    "mapping": {
+                        "type": "text",
+                        "analyzer": "folding",
+                        "fields": {
+                            "keyword": {
+                                "type": "keyword",
+                                "ignore_above": 256
+                            }
+                        }
+                    }
+                }
+            }
+        ],
+        "properties": {
+            "properties": {
+                "properties": {
+                    "age": {
+                        "type": "long"
+                    },
+                    "firstVisit": {
+                        "type": "date"
+                    },
+                    "lastVisit": {
+                        "type": "date"
+                    },
+                    "previousVisit": {
+                        "type": "date"
+                    },
+                    "nbOfVisits": {
+                        "type": "long"
+                    },
+                    "interests": {
+                        "type": "nested"
+                    }
+                }
+            },
+            "consents": {
+                "properties": {
+                    "statusDate": {
+                        "type": "date"
+                    },
+                    "revokeDate": {
+                        "type": "date"
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json b/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json
new file mode 100644
index 000000000..eedc60dcd
--- /dev/null
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json
@@ -0,0 +1,4 @@
+{
+    "source": "List interests = new ArrayList(); if(ctx._source.properties.interests != null && !(ctx._source.properties.interests instanceof List)){ for (entry in ctx._source.properties.interests.entrySet()){ Map interest = new HashMap(); interest.put('key',entry.getKey()); interest.put('value', entry.getValue()); interests.add(interest);} ctx._source.properties.remove('interests'); ctx._source.properties.put('interests',interests);}",
+    "lang": "painless"
+}