Add Elasticsearch routing for GLQL/Work Items Advanced Search
What does this MR do and why?
This MR fixes a performance issue in the GLQL/Work Items Advanced Search integration where Elasticsearch queries were not using shard routing, causing queries to search across ALL shards instead of targeting specific shards.
Problem: The Advanced Finder was not passing root_ancestor_ids to es_search_options, which prevented the Elastic::Latest::Routing module from building the routing parameter for Elasticsearch requests.
Solution: Add root_ancestor_ids to es_search_options, enabling Elasticsearch to route queries to the correct shard based on the root namespace ID.
Performance Impact: On large GitLab instances with multiple shards, this can provide up to 10x speedup by searching only the relevant shard(s) instead of all shards.
Note: root_ancestor_ids now serves two purposes:
-
In
base_params: Used for query filtering/authorization (already working) -
In
es_search_options: Used for Elasticsearch shard routing (added by this MR)
How to set up and validate locally
Prerequisites
- GDK with Elasticsearch enabled
- The
glql_es_integrationfeature flag enabled - Enable the new feature flag:
Feature.enable(:search_glql_use_routing)
Manual Testing
- Create a group with some work items
- Enable Advanced Search for the namespace
- Execute a GLQL query or Work Items List query
- Check Elasticsearch logs/monitoring for the routing parameter in the request
Observing the routing parameter
Before this change:
POST /gitlab-production-work-items/_search
{ "query": ... }
After this change:
POST /gitlab-production-work-items/_search?routing=group_123
{ "query": ... }
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related issues
Closes #580655 (closed)