jkevan commented on code in PR #427:
URL: https://github.com/apache/unomi/pull/427#discussion_r878247020


##########
tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo200.java:
##########
@@ -67,50 +73,31 @@ public void execute(Session session, CloseableHttpClient 
httpClient, String esAd
     }
 
     private void doExecute() throws IOException {
-        try (CloseableHttpResponse response = httpClient.execute(new 
HttpGet(esAddress + "/_aliases"))) {
-
-            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
-                JSONObject indicesAsJson = new 
JSONObject(EntityUtils.toString(response.getEntity()));
-
-                final Set<String> indices = indicesAsJson.keySet().stream().
-                        filter(alias -> alias.startsWith("context-event")).
-                        collect(Collectors.toSet());
-
-                for (String indexName : indices) {
-                    updateMapping(indexName, httpClient);
-                }
-            }
+        String indexPrefix = ConsoleUtils.askUserWithDefaultAnswer(session, 
"SOURCE index name (default: context) : ", "context");
+        Set<String> indexes = getEventIndexes(indexPrefix);
+        for (String index : indexes) {
+            updateMapping(index);
         }
+        createScopes(getSetOfScopes(indexes), indexPrefix);
     }
 
-    private void updateMapping(final String indexName, final 
CloseableHttpClient httpClient) throws IOException {
+    private void updateMapping(final String indexName) throws IOException {
         HttpPut httpPut = new HttpPut(esAddress + "/" + indexName + 
"/_mapping");
 
         httpPut.addHeader("Accept", "application/json");
         httpPut.addHeader("Content-Type", "application/json");
 
-        String request = "{\n" +
-                "\"properties\": {\n" +
-                " \"sourceId\": {\n" +
-                "  \"analyzer\": \"folding\",\n" +
-                "  \"type\": \"text\",\n" +
-                "  \"fields\": {\n" +
-                "   \"keyword\": {\n" +
-                "    \"type\": \"keyword\",\n" +
-                "    \"ignore_above\": 256\n" +
-                "    }\n" +
-                "   }\n" +
-                "  }\n" +
-                " }\n" +
-                "}";
+        String request = "{\n" + "\"properties\": {\n" + " \"sourceId\": {\n" 
+ "  \"analyzer\": \"folding\",\n" + "  \"type\": \"text\",\n"
+                + "  \"fields\": {\n" + "   \"keyword\": {\n" + "    \"type\": 
\"keyword\",\n" + "    \"ignore_above\": 256\n" + "    }\n"
+                + "   }\n" + "  }\n" + " }\n" + "}";

Review Comment:
   Difficult to maintain this kind of stuff, would be great to have them in 
separate file as resources like in the itests.
   I know that we dont update them after release, but in case of any issue or 
troubleshoot this code will be painful



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to