mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-07 13:07:22 +00:00
MINOR: Fix delete entity relation live indexing (#19837)
This commit is contained in:
parent
35ddce7e95
commit
65b5e6c808
@ -101,6 +101,7 @@ import org.openmetadata.service.jdbi3.FeedRepository.ThreadContext;
|
||||
import org.openmetadata.service.resources.databases.DatabaseUtil;
|
||||
import org.openmetadata.service.resources.databases.TableResource;
|
||||
import org.openmetadata.service.resources.feeds.MessageParser.EntityLink;
|
||||
import org.openmetadata.service.search.SearchClient;
|
||||
import org.openmetadata.service.security.mask.PIIMasker;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
@ -134,6 +135,8 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
public static final String COLUMN_FIELD = "columns";
|
||||
public static final String CUSTOM_METRICS = "customMetrics";
|
||||
|
||||
private static final SearchClient searchClient = Entity.getSearchRepository().getSearchClient();
|
||||
|
||||
public TableRepository() {
|
||||
super(
|
||||
TableResource.COLLECTION_PATH,
|
||||
@ -1267,6 +1270,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
EntityReference toTable = Entity.getEntityReferenceByName(TABLE, toParent, ALL);
|
||||
deleteRelationship(
|
||||
table.getId(), TABLE, toTable.getId(), TABLE, Relationship.RELATED_TO);
|
||||
searchRepository.deleteRelationshipFromSearch(table.getId(), toTable.getId());
|
||||
} catch (EntityNotFoundException e) {
|
||||
throw EntityNotFoundException.byName(
|
||||
String.format(
|
||||
|
||||
@ -85,6 +85,9 @@ public interface SearchClient {
|
||||
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) }}";
|
||||
|
||||
String REMOVE_ENTITY_RELATIONSHIP =
|
||||
"for (int i = 0; i < ctx._source.entityRelationship.length; i++) { if (ctx._source.entityRelationship[i].doc_id == '%s') { ctx._source.entityRelationship.remove(i) }}";
|
||||
|
||||
String ADD_UPDATE_LINEAGE =
|
||||
"boolean docIdExists = false; for (int i = 0; i < ctx._source.lineage.size(); i++) { if (ctx._source.lineage[i].doc_id.equalsIgnoreCase(params.lineageData.doc_id)) { ctx._source.lineage[i] = params.lineageData; docIdExists = true; break;}}if (!docIdExists) {ctx._source.lineage.add(params.lineageData);}";
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import static org.openmetadata.service.search.SearchClient.PROPAGATE_NESTED_FIEL
|
||||
import static org.openmetadata.service.search.SearchClient.PROPAGATE_TEST_SUITES_SCRIPT;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_DATA_PRODUCTS_CHILDREN_SCRIPT;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_DOMAINS_CHILDREN_SCRIPT;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_ENTITY_RELATIONSHIP;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_OWNERS_SCRIPT;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_PROPAGATED_ENTITY_REFERENCE_FIELD_SCRIPT;
|
||||
import static org.openmetadata.service.search.SearchClient.REMOVE_PROPAGATED_FIELD_SCRIPT;
|
||||
@ -1161,4 +1162,12 @@ public class SearchRepository {
|
||||
public Set<String> getSearchEntities() {
|
||||
return new HashSet<>(entityIndexMap.keySet());
|
||||
}
|
||||
|
||||
public void deleteRelationshipFromSearch(UUID fromTableId, UUID toTableId) {
|
||||
String relationDocId = fromTableId.toString() + "-" + toTableId.toString();
|
||||
searchClient.updateChildren(
|
||||
GLOBAL_SEARCH_ALIAS,
|
||||
new ImmutablePair<>("entityRelationship.doc_id.keyword", relationDocId),
|
||||
new ImmutablePair<>(String.format(REMOVE_ENTITY_RELATIONSHIP, relationDocId), null));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user