From ac5bbb1673fc54f262d6b22033d551c539b3dd8c Mon Sep 17 00:00:00 2001 From: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:07:00 +0530 Subject: [PATCH] Fix Certification tags not updating in ES (#18952) * Fix Certification tags not updating in ES * Move code to search repository --- .../service/jdbi3/TagRepository.java | 6 ++--- .../service/search/SearchClient.java | 3 +++ .../service/search/SearchRepository.java | 22 ++++++++++++++++++- .../resources/elasticsearch/indexMapping.json | 4 ++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java index 23fb53088cf..6ffa07b53f2 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TagRepository.java @@ -13,6 +13,7 @@ package org.openmetadata.service.jdbi3; +import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.schema.type.Include.ALL; import static org.openmetadata.schema.type.Include.NON_DELETED; import static org.openmetadata.service.Entity.CLASSIFICATION; @@ -31,7 +32,6 @@ import java.util.UUID; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.ImmutablePair; import org.jdbi.v3.sqlobject.transaction.Transaction; -import org.openmetadata.common.utils.CommonUtil; import org.openmetadata.schema.BulkAssetsRequestInterface; import org.openmetadata.schema.EntityInterface; import org.openmetadata.schema.api.AddTagToAssetsRequest; @@ -135,7 +135,7 @@ public class TagRepository extends EntityRepository { List failures = new ArrayList<>(); List success = new ArrayList<>(); - if (dryRun || CommonUtil.nullOrEmpty(request.getAssets())) { + if (dryRun || nullOrEmpty(request.getAssets())) { // Nothing to Validate return result .withStatus(ApiStatus.SUCCESS) @@ -176,7 +176,7 @@ public class TagRepository extends EntityRepository { result.setNumberOfRowsFailed(result.getNumberOfRowsFailed() + 1); } // Validate and Store Tags - if (CommonUtil.nullOrEmpty(result.getFailedRequest())) { + if (nullOrEmpty(result.getFailedRequest())) { List tempList = new ArrayList<>(asset.getTags()); tempList.add(tagLabel); // Apply Tags to Entities diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchClient.java index e5ecf353314..a02aaad5168 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchClient.java @@ -74,6 +74,9 @@ public interface SearchClient { String REMOVE_TAGS_CHILDREN_SCRIPT = "for (int i = 0; i < ctx._source.tags.length; i++) { if (ctx._source.tags[i].tagFQN == params.fqn) { ctx._source.tags.remove(i) }}"; + String UPDATE_CERTIFICATION_SCRIPT = + "if (ctx._source.certification != null && ctx._source.certification.tagLabel != null) {ctx._source.certification.tagLabel.style = params.style; ctx._source.certification.tagLabel.description = params.description; ctx._source.certification.tagLabel.tagFQN = params.tagFQN; ctx._source.certification.tagLabel.name = params.name; }"; + String REMOVE_LINEAGE_SCRIPT = "for (int i = 0; i < ctx._source.lineage.length; i++) { if (ctx._source.lineage[i].doc_id == '%s') { ctx._source.lineage.remove(i) }}"; diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java index 442cef3bffa..98f4477afdf 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java @@ -24,6 +24,7 @@ import static org.openmetadata.service.search.SearchClient.REMOVE_TAGS_CHILDREN_ import static org.openmetadata.service.search.SearchClient.REMOVE_TEST_SUITE_CHILDREN_SCRIPT; import static org.openmetadata.service.search.SearchClient.SOFT_DELETE_RESTORE_SCRIPT; import static org.openmetadata.service.search.SearchClient.UPDATE_ADDED_DELETE_GLOSSARY_TAGS; +import static org.openmetadata.service.search.SearchClient.UPDATE_CERTIFICATION_SCRIPT; import static org.openmetadata.service.search.SearchClient.UPDATE_PROPAGATED_ENTITY_REFERENCE_FIELD_SCRIPT; import static org.openmetadata.service.search.models.IndexMapping.indexNameSeparator; import static org.openmetadata.service.util.EntityUtil.compareEntityReferenceById; @@ -58,6 +59,7 @@ import org.openmetadata.schema.EntityInterface; import org.openmetadata.schema.EntityTimeSeriesInterface; import org.openmetadata.schema.analytics.ReportData; import org.openmetadata.schema.dataInsight.DataInsightChartResult; +import org.openmetadata.schema.entity.classification.Tag; import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration; import org.openmetadata.schema.tests.DataQualityReport; import org.openmetadata.schema.tests.TestSuite; @@ -366,7 +368,7 @@ public class SearchRepository { entityType, entityId, entity.getChangeDescription(), indexMapping, entity); propagateGlossaryTags( entityType, entity.getFullyQualifiedName(), entity.getChangeDescription()); - + propagateCertificationTags(entityType, entity); propagatetoRelatedEntities( entityType, entityId, entity.getChangeDescription(), indexMapping, entity); } catch (Exception ie) { @@ -452,6 +454,24 @@ public class SearchRepository { } } + public void propagateCertificationTags(String entityType, EntityInterface entity) { + ChangeDescription changeDescription = entity.getChangeDescription(); + if (changeDescription != null && entityType.equalsIgnoreCase(Entity.TAG)) { + Tag tagEntity = (Tag) entity; + if (tagEntity.getClassification().getFullyQualifiedName().equals("Certification")) { + Map paramMap = new HashMap<>(); + paramMap.put("name", entity.getName()); + paramMap.put("description", entity.getDescription()); + paramMap.put("tagFQN", entity.getFullyQualifiedName()); + paramMap.put("style", entity.getStyle()); + searchClient.updateChildren( + GLOBAL_SEARCH_ALIAS, + new ImmutablePair<>("certification.tagLabel.tagFQN", entity.getFullyQualifiedName()), + new ImmutablePair<>(UPDATE_CERTIFICATION_SCRIPT, paramMap)); + } + } + } + public void propagatetoRelatedEntities( String entityType, String entityId, diff --git a/openmetadata-service/src/main/resources/elasticsearch/indexMapping.json b/openmetadata-service/src/main/resources/elasticsearch/indexMapping.json index 99eef985c98..83a169b26f4 100644 --- a/openmetadata-service/src/main/resources/elasticsearch/indexMapping.json +++ b/openmetadata-service/src/main/resources/elasticsearch/indexMapping.json @@ -150,8 +150,8 @@ "indexName": "tag_search_index", "indexMappingFile": "/elasticsearch/%s/tag_index_mapping.json", "alias": "tag", - "parentAliases": ["classification","all", "dataAsset"], - "childAliases": [] + "parentAliases": ["classification"], + "childAliases": ["all", "dataAsset"] }, "classification": { "indexName": "classification_search_index",