Register assignee, created_at and updated_at filters for merge request search

🤖 AI-authored change.

What does this MR do and why?

Merge request search now accepts assignee, creation-date and update-date filters. All three fields were already indexed on the merge request document and no query ever read them.

  • Only the created_at range reaches the PostgreSQL path. Database Lab plans showed assignee_ids costs 367,678 buffers (2.8 GiB) against 636 for the same search today, so a275b4bd keeps the assignee and updated_at filters on Advanced Search only — the same way author_username and the branch filters already work.
  • No reindex and no migration. assignee_ids (type: :keyword) and created_at/updated_at (type: :date) are already mapped on master; this only queries them.
  • Malformed input is rejected up front: a bad date, or an assignee list over Search::Params::MAX_ASSIGNEE_IDS, gets a JSON 400 from #count and a flash alert from #show.
  • Milestone and reviewer filtering are out of scope — neither field is mapped, so they need a mapping change plus a backfill.
  • This is the backend half, and it ships unflagged. The filters are URL parameters only; no UI control and no API endpoint declares them, so reaching one means hand-editing a URL.

Reviewer focus: an oversized assignee list is left in raw_params rather than truncated, so a caller that ignores valid_assignee_ids? fails closed instead of searching a shortened list.

References

How to set up and validate locally

  1. Index a project with Advanced Search enabled.
  2. Visit /search?scope=merge_requests&search=<term>&assignee_ids[]=<id>&created_after=2026-01-01.
  3. Swap assignee_ids[] for not[assignee_ids][], and check updated_after/updated_before the same way.
  4. Repeat with Advanced Search disabled: only the created_at range applies.
  5. Pass created_after=not-a-date to see the rejection, on both /search and /search/count.

MR acceptance checklist

Evaluated against the MR acceptance checklist.


🤖 Automated change — mention me to get a response. Feedback welcome. Ask to speak to John directly anytime.

Mechanism, citations and verification (for agents / deep readers)

Mechanism

The three fields are already mapped on master in Elastic::Latest::MergeRequestConfig (assignee_ids as :keyword, created_at/updated_at as :date). Nothing here changes the mapping.

  • Search::Elastic::MergeRequestQueryBuilder adds by_assignees, by_created_at and by_updated_at to QUERY_COMPONENTS, and passes assignee_id_field: :assignee_ids in extra_options.
  • Search::Elastic::Filters gains ASSIGNEE_ID_FIELD; the clause builders read options.fetch(:assignee_id_field, ASSIGNEE_ID_FIELD), so existing assignee_id callers are byte-identical.
  • Gitlab::Elastic::SearchResults#merge_request_scope_options permits the six new keys. or_assignee_ids, none_assignees and any_assignees were registered too and removed in 76f914bf0798: no entry point can set them for this scope.
  • EE::Search::Filter#date_filters and EE::SearchController permit the params (including the not[assignee_ids] array form) and log six meta.search.filters.* keys.

PostgreSQL path: Gitlab::SearchResults#merge_request_finder_params is a new seam returning issuable_params. EE::Gitlab::SearchResults#merge_request_filter_params overrides it and forwards Search::Params::BASIC_SEARCH_DATE_PARAMS — created_after and created_before — and nothing else.

Validation: Search::Params adds DATE_PARAMS, MAX_ASSIGNEE_IDS and ASSIGNEE_ID_PARAMS, and #convert_all_date_params coerces every date to Time, recording and deleting anything unparseable. SearchController#count answers render json: {}, status: :bad_request rather than head :bad_request, matching render_timeout for the same action, because the sidebar count fetcher destructures JSON from every count response.

Verification

Pipeline https://gitlab.com/gitlab-org/gitlab/-/pipelines/2827971134 was green on the earlier head, including rubocop and danger-review.

On 76f914bf0798, run locally in a GDK worktree: spec/lib/search/params_spec.rb, ee/spec/lib/search/elastic/merge_request_query_builder_spec.rb, ee/spec/lib/search/elastic/filters_spec.rb (363 examples, 0 failures), ee/spec/lib/gitlab/elastic/search_results_merge_requests_spec.rb (42 examples, 0 failures); rubocop on the 8 touched files, no offenses; vale on the docs page, 0 errors.

The parity examples assert the divergence rather than dropping it: the shared example a filter Advanced Search applies and PostgreSQL ignores covers the assignee and updated_at filters.

Database review: query and plan

The only statement this adds to the basic PostgreSQL path is a created_at range. It is captured from SearchResults#merge_requests and measured on Database Lab (gitlab-production-main), not a local GDK.

SELECT "merge_requests".*
FROM "merge_requests"
INNER JOIN "projects" ON "projects"."id" = "merge_requests"."target_project_id"
LEFT JOIN project_features ON projects.id = project_features.project_id
WHERE (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 1614863 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (0, 10, 20))
AND ("project_features"."merge_requests_access_level" > 0 OR "project_features"."merge_requests_access_level" IS NULL)
AND "merge_requests"."created_at" <= '2026-09-09 00:00:00'
AND "merge_requests"."created_at" >= '2025-01-01 00:00:00'
AND (("merge_requests"."title" ILIKE '%api%') OR ("merge_requests"."description" ILIKE '%api%'))
AND "merge_requests"."target_project_id" IN (SELECT "projects"."id" FROM "projects" LEFT OUTER JOIN "namespaces" ON "namespaces"."type" = 'Group' AND "namespaces"."id" = "projects"."namespace_id" AND "namespaces"."type" = 'Group' WHERE (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 1614863 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (0, 10, 20)) AND "projects"."pending_delete" = FALSE AND "projects"."hidden" = FALSE AND "projects"."archived" = FALSE AND NOT (EXISTS (SELECT 1 FROM "namespace_settings" WHERE "namespace_settings"."namespace_id" = ANY (namespaces.traversal_ids) AND "namespace_settings"."archived" = TRUE)))
ORDER BY created_at DESC
LIMIT 20;
 Limit  (cost=3.13..396.30 rows=20 width=1037) (actual time=57.479..768.344 rows=20 loops=1)
   Buffers: shared hit=439 read=535 dirtied=17
   WAL: records=17 fpi=17 bytes=104369
   I/O Timings: read=755.293 write=0.000
   ->  Nested Loop Left Join  (cost=3.13..123305395.46 rows=6272387 width=1037) (actual time=57.478..768.328 rows=20 loops=1)
         Filter: ((project_features.merge_requests_access_level > 0) OR (project_features.merge_requests_access_level IS NULL))
         Buffers: shared hit=439 read=535 dirtied=17
         WAL: records=17 fpi=17 bytes=104369
         I/O Timings: read=755.293 write=0.000
         ->  Nested Loop Semi Join  (cost=2.57..118485011.67 rows=6024107 width=1041) (actual time=42.106..649.246 rows=20 loops=1)
               Buffers: shared hit=398 read=476 dirtied=16
               WAL: records=16 fpi=16 bytes=96388
               I/O Timings: read=636.638 write=0.000
               ->  Nested Loop  (cost=1.15..78219380.44 rows=6275381 width=1041) (actual time=29.658..423.613 rows=20 loops=1)
                     Buffers: shared hit=169 read=341 dirtied=10
                     WAL: records=10 fpi=10 bytes=65934
                     I/O Timings: read=412.502 write=0.000
                     ->  Index Scan Backward using index_merge_requests_on_created_at on public.merge_requests  (cost=0.57..75762864.32 rows=6275381 width=1037) (actual time=11.027..200.298 rows=20 loops=1)
                           Index Cond: ((merge_requests.created_at <= '2026-09-09 00:00:00+00'::timestamp with time zone) AND (merge_requests.created_at >= '2025-01-01 00:00:00+00'::timestamp with time zone))
                           Filter: (((merge_requests.title)::text ~~* '%api%'::text) OR (merge_requests.description ~~* '%api%'::text))
                           Rows Removed by Filter: 87
                           Buffers: shared hit=100 read=220
                           I/O Timings: read=196.611 write=0.000
                     ->  Memoize  (cost=0.57..4.94 rows=1 width=4) (actual time=11.162..11.162 rows=1 loops=20)
                           Cache Key: merge_requests.target_project_id
                           Cache Mode: logical
                           Hits: 0  Misses: 20  Evictions: 0  Overflows: 0  Memory Usage: 3kB
                           Buffers: shared hit=69 read=121 dirtied=10
                           WAL: records=10 fpi=10 bytes=65934
                           I/O Timings: read=215.891 write=0.000
                           ->  Index Scan using projects_pkey on public.projects  (cost=0.56..4.93 rows=1 width=4) (actual time=10.846..10.846 rows=1 loops=20)
                                 Index Cond: (projects.id = merge_requests.target_project_id)
                                 Filter: (EXISTS(SubPlan 1) OR (projects.visibility_level = ANY ('{0,10,20}'::integer[])))
                                 Buffers: shared hit=65 read=121 dirtied=6
                                 WAL: records=6 fpi=6 bytes=46298
                                 I/O Timings: read=215.891 write=0.000
                                 SubPlan 1
                                   ->  Index Only Scan using index_project_authorizations_on_project_user_access_level on public.project_authorizations  (cost=0.58..3.60 rows=1 width=0) (actual time=5.744..5.744 rows=0 loops=20)
                                         Index Cond: ((project_authorizations.project_id = projects.id) AND (project_authorizations.user_id = 1614863))
                                         Heap Fetches: 0
                                         Buffers: shared hit=23 read=57
                                         I/O Timings: read=114.515 write=0.000
               ->  Nested Loop Anti Join  (cost=1.42..6.41 rows=1 width=4) (actual time=11.279..11.279 rows=1 loops=20)
                     Buffers: shared hit=229 read=135 dirtied=6
                     WAL: records=6 fpi=6 bytes=30454
                     I/O Timings: read=224.136 write=0.000
                     ->  Nested Loop Left Join  (cost=1.13..5.22 rows=1 width=32) (actual time=10.280..10.280 rows=1 loops=20)
                           Buffers: shared hit=187 read=109 dirtied=6
                           WAL: records=6 fpi=6 bytes=30454
                           I/O Timings: read=204.481 write=0.000
                           ->  Index Scan using index_projects_on_id_and_archived_and_pending_delete on public.projects projects_1  (cost=0.56..4.41 rows=1 width=8) (actual time=4.114..4.114 rows=1 loops=20)
                                 Index Cond: (projects_1.id = projects.id)
                                 Filter: ((NOT projects_1.hidden) AND (EXISTS(SubPlan 3) OR (projects_1.visibility_level = ANY ('{0,10,20}'::integer[]))))
                                 Buffers: shared hit=142 read=49 dirtied=1
                                 WAL: records=1 fpi=1 bytes=7709
                                 I/O Timings: read=81.668 write=0.000
                                 SubPlan 3
                                   ->  Index Only Scan using index_project_authorizations_on_project_user_access_level on public.project_authorizations project_authorizations_1  (cost=0.58..3.60 rows=1 width=0) (actual time=0.007..0.007 rows=0 loops=20)
                                         Index Cond: ((project_authorizations_1.project_id = projects_1.id) AND (project_authorizations_1.user_id = 1614863))
                                         Heap Fetches: 0
                                         Buffers: shared hit=80
                                         I/O Timings: read=0.000 write=0.000
                           ->  Index Scan using namespaces_pkey on public.namespaces  (cost=0.57..0.81 rows=1 width=32) (actual time=6.161..6.161 rows=1 loops=20)
                                 Index Cond: (namespaces.id = projects_1.namespace_id)
                                 Filter: ((namespaces.type)::text = 'Group'::text)
                                 Buffers: shared hit=40 read=60
                                 I/O Timings: read=122.812 write=0.000
                     ->  Index Only Scan using index_namespace_settings_on_namespace_id_where_archived_true on public.namespace_settings  (cost=0.29..0.74 rows=1 width=4) (actual time=0.996..0.996 rows=0 loops=20)
                           Index Cond: (namespace_settings.namespace_id = ANY (namespaces.traversal_ids))
                           Heap Fetches: 0
                           Buffers: shared hit=42 read=26
                           I/O Timings: read=19.656 write=0.000
         ->  Index Scan using index_project_features_on_project_id on public.project_features  (cost=0.56..0.79 rows=1 width=8) (actual time=5.951..5.951 rows=1 loops=20)
               Index Cond: (project_features.project_id = projects.id)
               Buffers: shared hit=41 read=59 dirtied=1
               WAL: records=1 fpi=1 bytes=7981
               I/O Timings: read=118.655 write=0.000
Settings: effective_cache_size = '472585MB', work_mem = '230MB', jit = 'off', random_page_cost = '1.5', seq_page_cost = '4'
Query ID: 6381285819179591761

Supporting indexes are all already on master: index_merge_requests_on_created_at carries this plan as an index condition, the same scan master performs today. Plans for the shapes that were dropped in a275b4bd are at !254033 (comment 3875381219).

What I did not verify

  • No manual UI exercise of the new filters or of the two error paths (#count JSON 400, #show flash alert); both are covered only by the specs above.
  • The docs page was not rendered — doc/user/search/advanced_search.md was not built locally, only linted.
  • Cold timings on a shared Database Lab clone spread widely; the buffer counts are the load-bearing figure.
Edited by John Mason

Merge request reports

Loading
Loading