Fix Certification tags not updating in ES (#18952)

* Fix Certification tags not updating in ES

* Move code to search repository
This commit is contained in:
Mohit Yadav 2024-12-09 11:07:00 +05:30 committed by GitHub
parent b3c76292b8
commit ac5bbb1673
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 6 deletions

View File

@ -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<Tag> {
List<BulkResponse> failures = new ArrayList<>();
List<BulkResponse> 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<Tag> {
result.setNumberOfRowsFailed(result.getNumberOfRowsFailed() + 1);
}
// Validate and Store Tags
if (CommonUtil.nullOrEmpty(result.getFailedRequest())) {
if (nullOrEmpty(result.getFailedRequest())) {
List<TagLabel> tempList = new ArrayList<>(asset.getTags());
tempList.add(tagLabel);
// Apply Tags to Entities

View File

@ -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) }}";

View File

@ -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<String, Object> 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,

View File

@ -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",