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:49:22 UTC

[unomi] branch master updated: UNOMI-637 : do not create mapping for property type if not necessary (#469)

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

jsinovassinnaik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new e273b78d9 UNOMI-637 : do not create mapping for property type if not necessary (#469)
e273b78d9 is described below

commit e273b78d9d26a0843e7b0493a546b2df045b122f
Author: jsinovassin <58...@users.noreply.github.com>
AuthorDate: Tue Aug 2 15:49:17 2022 +0200

    UNOMI-637 : do not create mapping for property type if not necessary (#469)
    
    * UNOMI-637 : do not create mapping for property type if not necessary
---
 .../ElasticSearchPersistenceServiceImpl.java            | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 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 cd5183232..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,13 +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<>());
-            mergePropertiesMapping(subSubMappings, createPropertyMapping(property));
+
+            mergePropertiesMapping(subSubMappings, propertyMapping);
 
             Map<String, Object> mappingsWrapper = new HashMap<>();
             mappingsWrapper.put("properties", mappings);
@@ -1461,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)) {
@@ -1479,7 +1485,10 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
         if ("set".equals(property.getValueTypeId())) {
             Map<String, Object> childProperties = new HashMap<>();
             property.getChildPropertyTypes().forEach(childType -> {
-                mergePropertiesMapping(childProperties, createPropertyMapping(childType));
+                Map<String, Object> propertyMapping = createPropertyMapping(childType);
+                if (!propertyMapping.isEmpty()) {
+                    mergePropertiesMapping(childProperties, propertyMapping);
+                }
             });
             definition.put("properties", childProperties);
         }