From fa950659c342750ccdfa65674081fdb89deae8d3 Mon Sep 17 00:00:00 2001 From: neelesh thakur <nthakur4@slb.com> Date: Fri, 12 Aug 2022 14:17:38 +0000 Subject: [PATCH] Merge branch 'nested-text-array' into 'master' correctly resolve mapping for text array inside nested array object See merge request osdu/platform/system/indexer-service!358 (cherry picked from commit a32377edc994ef353a3770992fe8e306e285a96c) 9fb99c26 correctly resolve mapping for text array inside nested array object cc9fe5ad correctly resolve mapping for text array inside nested array object 186067cf NOTICE 95a1c11d rebase a3854473 Merge remote-tracking branch 'origin/master' into nested-text-array --- .../osdu/indexer/util/TypeMapper.java | 19 +++++++++++-------- .../service/IndexerMappingServiceTest.java | 9 ++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java index 08c93b9a7..022d662f3 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java @@ -14,10 +14,6 @@ package org.opengroup.osdu.indexer.util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.List; import org.apache.commons.lang3.StringUtils; import org.opengroup.osdu.core.common.Constants; import org.opengroup.osdu.core.common.model.entitlements.AclRole; @@ -26,6 +22,11 @@ import org.opengroup.osdu.core.common.model.indexer.Records; import org.opengroup.osdu.core.common.model.indexer.StorageType; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class TypeMapper { private static final Map<String, String> storageToIndexerType = new HashMap<>(); @@ -80,7 +81,7 @@ public class TypeMapper { //TODO temporary fix for https://community.opengroup.org/osdu/platform/system/indexer-service/-/issues/1 storageToIndexerType.put(STORAGE_TYPE_OBJECTS, ElasticType.OBJECT.getValue()); storageToIndexerType.put(STORAGE_TYPE_NESTED, ElasticType.NESTED.getValue()); - storageToIndexerType.put(STORAGE_TYPE_FLATTENED,ElasticType.FLATTENED.getValue()); + storageToIndexerType.put(STORAGE_TYPE_FLATTENED, ElasticType.FLATTENED.getValue()); } public static String getIndexerType(String storageType, String defaultType) { @@ -130,8 +131,10 @@ public class TypeMapper { for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) { if (isMap(entry.getValue())) { entry.setValue(getDataAttributeIndexerMapping(entry.getValue())); - } else if(ElasticType.TEXT.getValue().equalsIgnoreCase(String.valueOf(entry.getValue()))) { + } else if (ElasticType.TEXT.getValue().equalsIgnoreCase(String.valueOf(entry.getValue()))) { entry.setValue(getTextIndexerMapping()); + } else if (isArray(String.valueOf(entry.getValue()))) { + entry.setValue(Records.Type.builder().type(getArrayMemberType(String.valueOf(entry.getValue()))).build()); } else { entry.setValue(Records.Type.builder().type(entry.getValue().toString()).build()); } @@ -189,8 +192,8 @@ public class TypeMapper { public static Object getObjectsArrayMapping(String dataType, Object properties) { Map<String, Object> nestedMapping = new HashMap<>(); - nestedMapping.put(Constants.TYPE,storageToIndexerType.getOrDefault(dataType, dataType)); - nestedMapping.put(Constants.PROPERTIES,properties); + nestedMapping.put(Constants.TYPE, storageToIndexerType.getOrDefault(dataType, dataType)); + nestedMapping.put(Constants.PROPERTIES, properties); return nestedMapping; } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java index ec1f61e4b..45f23f8a2 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java @@ -57,7 +57,7 @@ public class IndexerMappingServiceTest { private final String kind = "tenant:test:test:1.0.0"; private final String index = "tenant-test-test-1.0.0"; private final String type = "test"; - private final String validMapping = "{\"dynamic\":false,\"properties\":{\"data\":{\"properties\":{\"Msg\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"null_value\":\"null\",\"ignore_above\":256,\"type\":\"keyword\"}}},\"Location\":{\"type\":\"geo_point\"}}},\"authority\":{\"type\":\"constant_keyword\",\"value\":\"tenant\"},\"id\":{\"type\":\"keyword\"},\"acl\":{\"properties\":{\"viewers\":{\"type\":\"keyword\"},\"owners\":{\"type\":\"keyword\"}}}}}"; + private final String validMapping = "{\"dynamic\":false,\"properties\":{\"data\":{\"properties\":{\"Msg\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"null_value\":\"null\",\"ignore_above\":256,\"type\":\"keyword\"}}},\"Intervals\":{\"properties\":{\"StopMarkerID\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"null_value\":\"null\",\"ignore_above\":256,\"type\":\"keyword\"}}},\"GeologicUnitInterpretationIDs\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"null_value\":\"null\",\"ignore_above\":256,\"type\":\"keyword\"}}},\"StopMeasuredDepth\":{\"type\":\"double\"}}},\"Location\":{\"type\":\"geo_point\"}}},\"authority\":{\"type\":\"constant_keyword\",\"value\":\"tenant\"},\"id\":{\"type\":\"keyword\"},\"acl\":{\"properties\":{\"viewers\":{\"type\":\"keyword\"},\"owners\":{\"type\":\"keyword\"}}}}}"; private final String emptyDataValidMapping = "{\"dynamic\":false,\"properties\":{\"id\":{\"type\":\"keyword\"},\"acl\":{\"properties\":{\"viewers\":{\"type\":\"keyword\"},\"owners\":{\"type\":\"keyword\"}}},\"authority\":{\"type\":\"constant_keyword\",\"value\":\"tenant\"}}}"; @Mock @@ -111,6 +111,13 @@ public class IndexerMappingServiceTest { Map<String, Object> dataMapping = new HashMap<>(); dataMapping.put("Location", "geo_point"); dataMapping.put("Msg", "text"); + Map<String, Object> intervalNestedAttribute = new HashMap<>(); + Map<String, Object> intervalProperties = new HashMap<>(); + intervalProperties.put("StopMarkerID", "text"); + intervalProperties.put("GeologicUnitInterpretationIDs", "text"); + intervalProperties.put("StopMeasuredDepth", "double"); + intervalNestedAttribute.put("properties", intervalProperties); + dataMapping.put("Intervals", intervalNestedAttribute); return dataMapping; } -- GitLab