Procházet zdrojové kódy

修复es索引中存在多个mapping时无法解析的问题

zhou-hao před 4 roky
rodič
revize
17ce3d2ecd

+ 8 - 3
jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/index/strategies/AbstractElasticSearchIndexStrategy.java

@@ -164,9 +164,13 @@ public abstract class AbstractElasticSearchIndexStrategy implements ElasticSearc
                 throw new UnsupportedOperationException("unsupported index metadata" + metaData);
             }
             properties = mappingMetadata.sourceAsMap();
-        }
-        if (metaData.size() == 1) {
-            Object res = metaData.values().iterator().next().value;
+        } else {
+            Object res;
+            if (metaData.size() == 1) {
+                res = metaData.values().iterator().next().value;
+            } else {
+                res = metaData.get("_doc");
+            }
             if (res instanceof MappingMetadata) {
                 mappingMetadata = ((MappingMetadata) res);
             } else if (res instanceof CompressedXContent) {
@@ -179,6 +183,7 @@ public abstract class AbstractElasticSearchIndexStrategy implements ElasticSearc
         if (properties == null) {
             throw new UnsupportedOperationException("unsupported index metadata" + metaData);
         }
+
         return new DefaultElasticSearchIndexMetadata(index, convertProperties(properties));
     }