Keep reindexed work items when deleting a group's old documents

What does this MR do and why?

Search::ElasticGroupAssociationDeletionWorker deletes a group's work item documents by running delete_by_query against the work items index, using routing: "group_<ancestor_id>" and a filter on namespace_id.

In Elasticsearch, routing on delete_by_query only selects which shard to search. It does not filter documents by their own routing value.

EE::Groups::TransferService runs this worker for the old root ancestor, with descendants included, after a group moves to a new root. By that point the group's work items may already be reindexed under the new root, with routing group_<new_root_id>. When the old and new routing values happen to land on the same shard, the delete also matches the reindexed documents, because they share the same namespace_id. The group's work items then disappear from search until they are next updated.

The fix adds a filter on a traversal_ids prefix of <ancestor_id>-. Work item documents have always carried traversal_ids, so documents still under the old root keep matching, and documents already reindexed under the new root no longer match. Deletes triggered by group destroy and by removal from limited indexing pass the current root, so they are unaffected by this change.

Found while adding the equivalent delete for group milestones in the MR linked below, which uses the same prefix filter.

References

Screenshots or screen recordings

Not applicable, this is a backend-only fix with no UI change.

How to set up and validate locally

  1. With Advanced Search enabled, create group A with subgroup S, and add a group-level work item (epic) to S.
  2. Transfer S to be a subgroup of another top-level group B.
  3. Once indexing catches up, search for the work item as a member of S. Before this fix, the work item could be missing from results depending on shard placement. After this fix, it is always found, routed by group_<B id>, with no copy left under A.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading