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:

  1. In base_params: Used for query filtering/authorization (already working)
  2. 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_integration feature flag enabled
  • Enable the new feature flag: Feature.enable(:search_glql_use_routing)

Manual Testing

  1. Create a group with some work items
  2. Enable Advanced Search for the namespace
  3. Execute a GLQL query or Work Items List query
  4. 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)

Edited by Dmitry Gruzd

Merge request reports

Loading