From 9e9ca9b75baf802834779bca4c9b7f68fbb0cc56 Mon Sep 17 00:00:00 2001 From: milindgupta Date: Fri, 26 Jul 2024 10:00:09 +0530 Subject: [PATCH] Fix: bug fix for empty key values pair in elastic search mapping --- .../search/transformer/SearchDocumentTransformer.java | 6 ++++-- .../src/test/java/com/linkedin/metadata/TestEntityUtil.java | 2 ++ .../search/transformer/SearchDocumentTransformerTest.java | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/metadata-io/src/main/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformer.java b/metadata-io/src/main/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformer.java index dd36f0a9456a74..bff6ebdd317c44 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformer.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformer.java @@ -287,8 +287,10 @@ public void setSearchableValue( .forEach( fieldValue -> { String[] keyValues = fieldValue.toString().split("="); - String key = keyValues[0]; - String value = keyValues[1]; + String key = keyValues[0], value = ""; + if (keyValues.length > 1) { + value = keyValues[1]; + } dictDoc.put(key, value); }); searchDocument.set(fieldName, dictDoc); diff --git a/metadata-io/src/test/java/com/linkedin/metadata/TestEntityUtil.java b/metadata-io/src/test/java/com/linkedin/metadata/TestEntityUtil.java index 9ee4a16a3ab991..062041253aa1fe 100644 --- a/metadata-io/src/test/java/com/linkedin/metadata/TestEntityUtil.java +++ b/metadata-io/src/test/java/com/linkedin/metadata/TestEntityUtil.java @@ -65,6 +65,8 @@ public static TestEntityInfo getTestEntityInfo(Urn urn) { "value1", "key2", "value2", + "key3", + "", "shortValue", "123", "longValue", diff --git a/metadata-io/src/test/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformerTest.java b/metadata-io/src/test/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformerTest.java index def14f9be7054a..0723859b124528 100644 --- a/metadata-io/src/test/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformerTest.java +++ b/metadata-io/src/test/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformerTest.java @@ -85,6 +85,7 @@ public void testTransform() throws IOException { assertEquals(parsedJson.get("feature2").asInt(), 1); JsonNode browsePathV2 = (JsonNode) parsedJson.get("browsePathV2"); assertEquals(browsePathV2.asText(), "␟levelOne␟levelTwo"); + assertEquals(parsedJson.get("esObjectField").get("key3").asText(), ""); } @Test