You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/12 17:03:08 UTC

[doris] 24/33: [Bug](ES): Es object mapping error (#18382)

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

morningman pushed a commit to branch doris-for-zhongjin
in repository https://gitbox.apache.org/repos/asf/doris.git

commit d369475844c8877ff08229b7f8fc415db65756e7
Author: Stalary <st...@163.com>
AuthorDate: Thu Apr 6 14:11:09 2023 +0800

    [Bug](ES): Es object mapping error (#18382)
    
    Issue Number: close #18379
---
 .../doris/external/elasticsearch/EsUtil.java       |  3 ++
 .../doris/external/elasticsearch/EsUtilTest.java   |  9 +++++
 .../data/es/es6_dynamic_complex_type.json          | 38 ++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/elasticsearch/EsUtil.java b/fe/fe-core/src/main/java/org/apache/doris/external/elasticsearch/EsUtil.java
index d4bdb2ffb8..b2a5ff4d04 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/elasticsearch/EsUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/elasticsearch/EsUtil.java
@@ -215,6 +215,9 @@ public class EsUtil {
     }
 
     private static ObjectNode replaceFieldAlias(ObjectNode mappingProps, ObjectNode fieldValue) {
+        if (!fieldValue.has("type")) {
+            return fieldValue;
+        }
         String typeStr = fieldValue.get("type").asText();
         if ("alias".equals(typeStr)) {
             String path = fieldValue.get("path").asText();
diff --git a/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/EsUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/EsUtilTest.java
index bf51af0c80..a6327fab6b 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/EsUtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/external/elasticsearch/EsUtilTest.java
@@ -259,4 +259,13 @@ public class EsUtilTest extends EsTestCase {
         Assertions.assertEquals("text", parseColumns.get(4).getType().toSql());
     }
 
+    @Test
+    public void testComplexType() throws IOException, URISyntaxException {
+        ObjectNode testFieldAlias = EsUtil.getRootSchema(
+                EsUtil.getMapping(loadJsonFromFile("data/es/es6_dynamic_complex_type.json")), null, new ArrayList<>());
+        List<Column> columns = EsUtil.genColumnsFromEs("test_complex_type", "complex_type", testFieldAlias, true,
+                new ArrayList<>());
+        Assertions.assertEquals(3, columns.size());
+    }
+
 }
diff --git a/fe/fe-core/src/test/resources/data/es/es6_dynamic_complex_type.json b/fe/fe-core/src/test/resources/data/es/es6_dynamic_complex_type.json
new file mode 100644
index 0000000000..c07cc52e72
--- /dev/null
+++ b/fe/fe-core/src/test/resources/data/es/es6_dynamic_complex_type.json
@@ -0,0 +1,38 @@
+{
+  "test_complex_type": {
+    "mappings": {
+      "complex_type": {
+        "dynamic": "true",
+        "properties": {
+          "account": {
+            "properties": {
+              "test1": {
+                "type": "double"
+              },
+              "test2": {
+                "type": "double"
+              },
+              "test3": {
+                "type": "double"
+              },
+              "test4": {
+                "type": "double"
+              }
+            }
+          },
+          "mobile": {
+            "type": "nested",
+            "properties": {
+              "first": {
+                "type": "text"
+              },
+              "last": {
+                "type": "keyword"
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org