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 08c93b9a7f7cfd04c44dede99018fe0d8148df01..022d662f3653a77ac68f8740639af5f70b76069f 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 ec1f61e4bf77cb496265cfc3142ebcbe77c4e71b..45f23f8a255188ede7d8c0861b566da26a8ab64f 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; }