Repository navigation
Fixes #35879: Preserve remaining search fields and refresh move and label copies - #36256
Conversation
…search - Moving a container or a knowledge page rewrote, by a bare text prefix, the FQN of every document whose FQN started with the old one: a sibling such as "rawdata" when "raw" moved, and documents of other types that happened to start the same way. The rewrite now matches the moved entity and what is under it, and replaces only the leading FQN segments. - Changing a team's users through a team PATCH did not re-index those users, so their teams went stale in search. - A user's display-name change now also reaches query users, knowledge page editors and file lastModifiedBy.
…-reading entities A full reindex, the retry-queue replay, reindexEntities and the live updateEntity(ref) path load each entity with its index's required field list. Fields its repository only loads on request were missing from the list, so the search document lost them: - usageSummary for pipelines, dashboards, ML models and schemas. Usage reports re-index through updateEntity(ref), so live usage never reached search for these types. - users on queries, which the Table > Queries panel reads from search. - lastLoginTime and lastActivityTime on users, which the Online Users search filters on. - folder on context files, which the Context Center Documents page filters on. - primaryEntity, relatedEntities, sourceEntity and sourceFile on context memories, which the asset memories listing filters on. Reporting usage for an ML model also failed with "Entity not found: chart": mlModelEntityUsage re-read the model as a chart.
…ts and object labels
| t.field(prefixFieldCondition) | ||
| .value(FieldValue.of(oldParentFQN)))) | ||
| .should( | ||
| s -> | ||
| s.prefix( | ||
| p -> | ||
| p.field(prefixFieldCondition) | ||
| .value(oldParentFQN + Entity.SEPARATOR))) |
There was a problem hiding this comment.
Container moves rename unrelated files
The boundary check still leaves the intended index restriction incomplete. ContainerRepository.updateAssetIndexes passes GLOBAL_SEARCH_ALIAS, and both Elasticsearch and OpenSearch filter only by fullyQualifiedName. Service names can repeat across service types, so a container and a file can both have svc.raw as their FQN. Moving that container also rewrites the file's search document, although its saved path never changed.
Target the container's write index and add a regression test with matching FQNs across entity types.
There was a problem hiding this comment.
Fixed in 4616c73: ContainerRepository.updateAssetIndexes now rewrites only the container write index, as page moves already do. New RenameCascadeSearchIT.containerMove_leavesOtherTypesWithTheSameFqnAlone gives a database and a container the same FQN (same-named database and storage services). On the global-alias rewrite it failed: the database doc became ….archive.raw. It passes now.
mohityadav766
left a comment
There was a problem hiding this comment.
Reviewed the latest head against current main, #35879 and merged #35888. Although #35879 is closed, this follow-up still contains absent fixes: PUT followers/votes and inheritance, reindex field hydration, membership refreshes and copied labels. It is not superseded by the earlier tag-preservation fix. The existing P1 about container moves targeting the global search alias remains applicable; I am not duplicating it inline. No additional substantiated finding from this static pass. The latest service-unit workflow failed, broad integration lanes were skipped, and the PR remains draft pending integration validation. Please resolve the existing index-scoping finding and validate the search/cascade cases on both engines before treating this as ready. No tests run locally.
Reviewed head: ab5f5f0dd223f4fbfb464e7d78d4075a480e6f81.
harshach
left a comment
There was a problem hiding this comment.
Good follow-up overall, especially on the boundary-safe FQN scripts, soft-deleted cascade reindexing, and the ML model usage fix. Two blockers need to be resolved before merge: domain_index_mapping.json does not map parent (so parent.id is dynamically analyzed as text and updateReferenceCopies will match zero subdomains), and ContainerRepository.updateAssetIndexes still targets GLOBAL_SEARCH_ALIAS instead of the container index. Please also address the performance regressions flagged inline — the N+1 getQueryUsers call in QueryRepository.clearFields, duplicate parent-inheritance traversal on changed PUTs, and unguarded consolidation replays in TeamRepository.updateChangedUsers — along with extending ReindexFieldSetSearchDocIT to verify usageSummary after reindexing.
| if (operation.isPatch() || operation.isPut()) { | ||
| try (var ignored = phase("updateSetInheritedFields")) { | ||
| setInheritedFields(updated, operation.isPatch() ? patchFields : putFields); | ||
| } | ||
| } |
There was a problem hiding this comment.
Calling setInheritedFields(updated, putFields) in reactUpdate causes every changed PUT (and import PUT) to traverse the parent inheritance chain twice, because applyPut (line 4848) and putForImportAndStore (line 4899) still call setInheritedFields(updated, new Fields(allowedFields)) right after update() returns. Resolve with new Fields(allowedFields) here (or track that inheritance already ran) and skip the post-update call in applyPut/putForImportAndStore when a change occurred.
| if (operation.isPatch() || operation.isPut()) { | |
| try (var ignored = phase("updateSetInheritedFields")) { | |
| setInheritedFields(updated, operation.isPatch() ? patchFields : putFields); | |
| } | |
| } |
There was a problem hiding this comment.
Done. reactUpdate resolves a PUT with new Fields(allowedFields) and records it; applyPut and putForImportAndStore skip their call when it ran. A PUT that changed nothing still resolves in applyPut, since reactUpdate returns early there.
| if (operation.isPut()) { | ||
| updated.setFollowers(original.getFollowers()); | ||
| updated.setVotes(original.getVotes()); | ||
| } |
There was a problem hiding this comment.
updateInternalForImport (line 11042) also runs under Operation.PUT and feeds reactUpdate() -> postUpdate() for search indexing, but still does not carry followers and votes from original. Copy them there too (or share a small helper with updateInternal) so import PUTs do not blank followers and votes in search.
There was a problem hiding this comment.
Done. updateInternal and updateInternalForImport share keepFieldsPutCannotChange(). The only caller of the single import path today is test-case CSV import, where followers come from the table through inheritance, so this keeps the two paths consistent rather than changing a visible result.
| Set<UUID> updatedUserIds = | ||
| updatedUsers.stream().map(EntityReference::getId).collect(Collectors.toSet()); | ||
| reindexMembership( | ||
| updatedTeam, | ||
| Stream.concat( | ||
| addedUsers.stream().map(EntityReference::getId), | ||
| origUserIds.stream().filter(id -> !updatedUserIds.contains(id))) | ||
| .toList()); |
There was a problem hiding this comment.
Guard reindexMembership(...) with if (isIndexBaselinePass()) (matching TableRepository.java:2454): during same-session change consolidation, updateChangedUsers runs across multiple replay passes and will enqueue duplicate post-commit DB reads and bulk search writes on every pass. Also consider avoiding re-adding team.getEntityReference() on this updater path since TeamUpdater's postUpdate already re-indexes updatedTeam.
| Set<UUID> updatedUserIds = | |
| updatedUsers.stream().map(EntityReference::getId).collect(Collectors.toSet()); | |
| reindexMembership( | |
| updatedTeam, | |
| Stream.concat( | |
| addedUsers.stream().map(EntityReference::getId), | |
| origUserIds.stream().filter(id -> !updatedUserIds.contains(id))) | |
| .toList()); |
There was a problem hiding this comment.
Done. The members are re-indexed only when isIndexBaselinePass(), and the updater path re-indexes just the users; the team document is left to postUpdate. The /users endpoints, which run no updater, still re-index the team too.
| "users"), | ||
| Entity.TEAM, List.of(FIELD_OWNERS, FIELD_REVIEWERS, "teams", "parents"), | ||
| Entity.DOMAIN, List.of(FIELD_DOMAINS), | ||
| Entity.DOMAIN, List.of(FIELD_DOMAINS, "parent"), |
There was a problem hiding this comment.
Adding "parent" here will not relabel subdomain documents in Elasticsearch/OpenSearch because domain_index_mapping.json has no parent mapping (only parentId), so parent.id is dynamically mapped as analyzed text (splitting UUIDs on -). Since updateReferenceCopies queries terms on parent.id, it will match zero subdomains; add an explicit parent object mapping with id as keyword to all domain_index_mapping.json files (or also match parent.id.keyword).
| Entity.DOMAIN, List.of(FIELD_DOMAINS, "parent"), |
There was a problem hiding this comment.
Fixed on the query side, for both engines: updateReferenceCopies matches object copies on <path>.id and on <path>.id.keyword. Existing domain indexes already map parent dynamically as text, and an explicit keyword mapping would only reach indexes rebuilt after upgrading, so matching the keyword sub-field covers both. It is the fallback anyOfFieldQuery already uses for the parent.id child update. domainDisplayName_reachesSubdomainParent, which failed in both CI IT lanes, passes on MySQL/ES and Postgres/OpenSearch.
| // query_search_index and Table → Queries renders the empty state. | ||
| fields.add("queryUsedIn"); | ||
| // "users" is stripped from storage JSON the same way; the Queries panel lists them from here. | ||
| fields.add("users"); |
There was a problem hiding this comment.
Adding "users" to QueryIndex.getRequiredReindexFields() triggers an N+1 DB query on every query reindex batch because QueryRepository.clearFields (line 115) calls this.getQueryUsers(entity) instead of entity.getUsers(), discarding the batch result that fetchAndSetQueryUsers just loaded on line 128. Change QueryRepository.clearFields line 115 to entity.getUsers() alongside this change so bulk query reindexing stays batched.
| fields.add("users"); |
There was a problem hiding this comment.
Done: clearFields keeps entity.getUsers(). The batch loader returned something else than getQueryUsers (any USES source, deleted users included), which the re-read had been masking, so fetchAndSetQueryUsers now applies the single read's rules too: users only, not deleted, one relationship read and one reference read per batch. That surfaced a bug in EntityRepository.findFromRecordsBatch, which passed the from and to types to the DAO swapped; fixed, and its only other caller uses one type for both. QueryResourceIT.test_batchFetchQueryFields covers the list path.
| // usageSummary is fields-gated in these repositories. A reindex dropped it, and a live usage | ||
| // report never landed at all: UsageRepository re-reads through updateEntity(ref), which loads | ||
| // only these fields, so the doc kept no usage and the usage-based ranking boosts had nothing. |
There was a problem hiding this comment.
Update this comment to match current UsageRepository.updateUsageInSearch: live usage reports now patch usageSummary directly via updateEntityFieldInSearch rather than calling updateEntity(ref), so this field set is what keeps usageSummary from being wiped on full reindex and reference-based rebuilds.
| // usageSummary is fields-gated in these repositories. A reindex dropped it, and a live usage | |
| // report never landed at all: UsageRepository re-reads through updateEntity(ref), which loads | |
| // only these fields, so the doc kept no usage and the usage-based ranking boosts had nothing. |
There was a problem hiding this comment.
Updated the comment.
| private static void assertUsageReachesSearchDoc(String entityType, String index, UUID id) { | ||
| SdkClients.adminClient() | ||
| .getHttpClient() | ||
| .execute( | ||
| HttpMethod.POST, | ||
| "/v1/usage/" + entityType + "/" + id, | ||
| new DailyCount().withDate(LocalDate.now().toString()).withCount(DAILY_USAGE), | ||
| EntityUsage.class); | ||
| awaitDocAsserted( | ||
| index, | ||
| id, | ||
| doc -> | ||
| assertEquals( | ||
| DAILY_USAGE, doc.path("usageSummary").path("dailyStats").path("count").asInt())); | ||
| } |
There was a problem hiding this comment.
Because UsageRepository.updateUsageInSearch patches usageSummary directly via updateEntityFieldInSearch without loading getRequiredReindexFields(), these three usage tests would still pass even if PipelineIndex, DashboardIndex, and MlModelIndex dropped "usageSummary" from their reindex field sets. After asserting the live usage write, delete the search doc and invoke /v1/search/reindexEntities (just as singleEntityReindex_keepsQueryUsers does) so the reindex path is actually verified.
| private static void assertUsageReachesSearchDoc(String entityType, String index, UUID id) { | |
| SdkClients.adminClient() | |
| .getHttpClient() | |
| .execute( | |
| HttpMethod.POST, | |
| "/v1/usage/" + entityType + "/" + id, | |
| new DailyCount().withDate(LocalDate.now().toString()).withCount(DAILY_USAGE), | |
| EntityUsage.class); | |
| awaitDocAsserted( | |
| index, | |
| id, | |
| doc -> | |
| assertEquals( | |
| DAILY_USAGE, doc.path("usageSummary").path("dailyStats").path("count").asInt())); | |
| } |
There was a problem hiding this comment.
Done. Each usage test now deletes the doc after the live write, calls /v1/search/reindexEntities, and asserts usage again (*Reindex_keepsUsage). Without usageSummary in PipelineIndex's field set, pipelineReindex_keepsUsage fails (usage 0 after the rebuild).
…trim PUT and team overhead - Container moves rewrite only the container index. Services of different types may share a name, so a database could hold the moved container's FQN and was renamed with it. - The relabel query also matches an object copy's id on its keyword sub-field. The domain mapping has no parent, so a subdomain's parent id is dynamically mapped as text and the exact match found no subdomain. - A changed PUT resolves inherited fields once, with every field, before indexing, and its caller no longer repeats the walk. Import PUTs keep followers and votes as regular PUTs do. - A team update re-indexes the users it added or removed only on the pass against the stored team, and leaves the team's own document to the update. - Query lists keep the users loaded in one batch, now read with the single read's rules (users only, not deleted), instead of re-reading each query's users in clearFields. findFromRecordsBatch passed the from and to entity types to the DAO swapped; its only other caller uses one type for both. - The usage ITs rebuild the document from a reindex read: a live usage report patches usageSummary directly, so it never exercised the field set. - SearchRepositoryTest stubs the overload updateEntitiesByReference delegates to.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved 🟡 Medium riskChanges shared entity-update and search reindexing paths across multiple entity types; regressions could leave search documents stale or mislabel copied references. Preserves search fields across entity PUT/PATCH updates, reindex reads, team membership changes, and copied labels, and limits container and knowledge-page move rewrites to their own index. No open issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
…ompile (#39703) #39624 backported StoredParentReferenceIT, which calls SearchDocs.awaitDocAsserted. That helper came in on main with #36256 and was never backported, so openmetadata-integration-tests fails to test-compile on 2.1. Bring over just the helper. Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #35879
Follow-up to merged #35888. Additional paths still overwrite complete search documents with partial entities or leave copied fields stale.
Changes:
users, pageeditorsand filelastModifiedBy.usageSummaryfor dashboards, pipelines, ML models and schemas; query users; user activity timestamps; context-file folders; context-memory source references. ML-model usage refresh reads the model as an ML model, not a chart.parent. Object copies are matched on the id and on its keyword sub-field, because a copy no mapping declares (a subdomain'sparent) is mapped dynamically as text.clearFields.Regression coverage:
EntityUpdateSearchDocIT: PUT followers/votes, inherited domains, retained tags, and PATCH owner inheritance.ReindexFieldSetSearchDocIT: usage and query users survive a rebuild from a reindex read (/v1/search/reindexEntitiesafter deleting the doc).RenameCascadeSearchIT: container moves leave siblings and other entity types with the same FQN alone; page moves; soft-deleted tags/terms.TeamMembershipSearchITfor PATCH;ReferenceLabelSearchITfor query users and subdomain parent labels.SearchRepositoryTestcovers theIncludeoverload ofupdateEntitiesByReference.Validation on 4616c73 (main merged in 1ce632a):
containerMove_leavesOtherTypesWithTheSameFqnAlonefails on the global-alias rewrite (the database doc became….archive.raw), andpipelineReindex_keepsUsagefails withoutusageSummaryinPipelineIndex's field set (usage 0 after the rebuild). Both pass with the fixes.domainDisplayName_reachesSubdomainParentfailed in both CI IT lanes on the previous head and passes now.SearchRepositoryTest,SearchRepositoryBehaviorTest,SearchIndexFactoryTest,UpdateByQueryReconcilerTest,SearchClientTagScriptSeparationTest,SearchIndexReindexFieldsParityTest,ContainerRepositoryParentValidationTest,QueryRepository*Test,TeamRepositoryUnitTest,EntityLoaderIndirectionTest).ContainerResourceIT,QueryResourceIT,TeamResourceIT,UserResourceIT,DomainResourceIT,DataProductResourceIT,KnowledgePageHierarchyIT,TestCaseResourceITandGlossaryTermResourceIT: 2541 tests, 194 skipped. Two failures:QueryResourceIT.test_batchFetchQueryFieldsfound thatfindFromRecordsBatchpassed the from and to types to the DAO swapped (fixed; rerun ofQueryResourceIT,GlossaryTermResourceIT,ReindexFieldSetSearchDocITandReferenceLabelSearchIT: 604 tests, 0 failures), and theDataProductResourceITtest below.DataProductResourceIT.test_forgedDomainFqnCannotBypassTheDomainRule. It does not come from this PR: Fixes 37376: Let data products take assets from subdomains of their domain #39252 added it assertingInvalidRequestExceptionfromtables().update(), but the SDK'sEntityServiceBase.updatewraps every error inOpenMetadataException, so it cannot pass as written. The server returns the expected 400.Still outside this PR:
🤖 Generated with Claude Code
Restrict container move writes to the container index before merging.
Findings
Summary
Preserves fields during entity updates and reindexing, refreshes team membership and copied labels, and includes deleted descendants in rename refreshes.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Container moves] --> B[Update matching FQN through all] B --> C[Container documents renamed] B --> D[File with matching FQN also renamed] D --> E[Search path differs from saved file]Reviews (1) · Last reviewed commit: "fix(search): preserve PUT relationships ..." · Reviewed by Greptile