diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java index 29a16d2f599..d37149a872e 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java @@ -15,7 +15,7 @@ import org.openmetadata.service.search.SearchIndexUtils; import org.openmetadata.service.search.models.SearchSuggest; public record TestCaseIndex(TestCase testCase) implements SearchIndex { - private static final Set excludeFields = Set.of("testSuites.changeDescription"); + private static final Set excludeFields = Set.of("changeDescription"); @Override public Object getEntity() { @@ -23,8 +23,12 @@ public record TestCaseIndex(TestCase testCase) implements SearchIndex { } @Override - public Set getExcludedFields() { - return excludeFields; + public void removeNonIndexableFields(Map esDoc) { + SearchIndex.super.removeNonIndexableFields(esDoc); + List> testSuites = (List>) esDoc.get("testSuites"); + for (Map testSuite : testSuites) { + SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields); + } } @SneakyThrows diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java index a74422d8604..af6e6da9ed3 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java @@ -96,6 +96,7 @@ import org.openmetadata.service.resources.EntityResourceTest; import org.openmetadata.service.resources.databases.TableResourceTest; import org.openmetadata.service.resources.feeds.FeedResourceTest; import org.openmetadata.service.resources.feeds.MessageParser; +import org.openmetadata.service.search.indexes.TestCaseIndex; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.ResultList; import org.openmetadata.service.util.TestUtils; @@ -2026,6 +2027,30 @@ public class TestCaseResourceTest extends EntityResourceTest createEntity(invalidTestCaseMixedTypes, ADMIN_AUTH_HEADERS), BAD_REQUEST, "Value"); } + @Test + void test_testCaseEsDocCleanUp(TestInfo testInfo) { + TestCase testCase = + new TestCase() + .withId(UUID.randomUUID()) + .withChangeDescription(new ChangeDescription()) + .withTestSuites( + List.of( + new TestSuite() + .withId(UUID.randomUUID()) + .withChangeDescription(new ChangeDescription()), + new TestSuite() + .withId(UUID.randomUUID()) + .withChangeDescription(new ChangeDescription()))); + + Map doc = JsonUtils.convertValue(testCase, Map.class); + + TestCaseIndex testCaseIndex = new TestCaseIndex(testCase); + testCaseIndex.removeNonIndexableFields(doc); + assertNull(doc.get("changeDescription")); + List> testSuites = (List>) doc.get("testSuites"); + assertNull(testSuites.get(0).get("changeDescription")); + } + public void deleteTestCaseResult(String fqn, Long timestamp, Map authHeaders) throws HttpResponseException { WebTarget target = getCollection().path("/" + fqn + "/testCaseResult/" + timestamp);