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/08/02 13:40:32 UTC

[unomi] branch UNOMI-637-fix-mapping-creation updated: feedbacks

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

jsinovassinnaik pushed a commit to branch UNOMI-637-fix-mapping-creation
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/UNOMI-637-fix-mapping-creation by this push:
     new 016be9736 feedbacks
016be9736 is described below

commit 016be9736ac81696b42578c36dca580b21918b1f
Author: jsinovassin <js...@jahia.com>
AuthorDate: Tue Aug 2 15:40:23 2022 +0200

    feedbacks
---
 .../ElasticSearchPersistenceServiceImpl.java          | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index fcc95f791..27bdd35b3 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -1438,16 +1438,19 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
 
     public void setPropertyMapping(final PropertyType property, final String itemType) {
         try {
+            Map<String, Object> propertyMapping = createPropertyMapping(property);
+            if (propertyMapping.isEmpty()) {
+                return;
+            }
+
             Map<String, Map<String, Object>> mappings = getPropertiesMapping(itemType);
             if (mappings == null) {
                 mappings = new HashMap<>();
             }
             Map<String, Object> subMappings = mappings.computeIfAbsent("properties", k -> new HashMap<>());
             Map<String, Object> subSubMappings = (Map<String, Object>) subMappings.computeIfAbsent("properties", k -> new HashMap<>());
-            Map<String, Object> propertyMapping = createPropertyMapping(property);
-            if (propertyMapping != null) {
-                mergePropertiesMapping(subSubMappings, propertyMapping);
-            }
+
+            mergePropertiesMapping(subSubMappings, propertyMapping);
 
             Map<String, Object> mappingsWrapper = new HashMap<>();
             mappingsWrapper.put("properties", mappings);
@@ -1464,8 +1467,8 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
         final HashMap<String, Object> definition = new HashMap<>();
 
         if (esType == null) {
-            logger.warn("No predefined type found for property[" + property.getValueTypeId() + "], letting ES decide");
-            // we don't have a fixed type for that property so let ES decide it
+            logger.warn("No predefined type found for property[{}], no mapping will be created", property.getValueTypeId());
+            return Collections.emptyMap();
         } else {
             definition.put("type", esType);
             if ("text".equals(esType)) {
@@ -1483,14 +1486,14 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
             Map<String, Object> childProperties = new HashMap<>();
             property.getChildPropertyTypes().forEach(childType -> {
                 Map<String, Object> propertyMapping = createPropertyMapping(childType);
-                if (propertyMapping != null) {
+                if (!propertyMapping.isEmpty()) {
                     mergePropertiesMapping(childProperties, propertyMapping);
                 }
             });
             definition.put("properties", childProperties);
         }
 
-        return !definition.isEmpty() ? Collections.singletonMap(property.getItemId(), definition) : null;
+        return Collections.singletonMap(property.getItemId(), definition);
     }
 
     private String convertValueTypeToESType(String valueTypeId) {