Fix Advanced Search error for blank search terms
What does this MR do and why?
Fixes a crash in Advanced Search when the search term is blank or only whitespace.
In Elastic::Latest::ApplicationClassProxy#basic_query_hash, the blank-query branch now includes filter: [] in query.bool. This gives it the same shape as the non-blank branch.
Code that runs later appends to that array: Search::Elastic::Filters#add_filter and SnippetClassProxy#filter. Without the array, they raised NoMethodError (undefined method 'concat' for nil and undefined method '<<' for nil). One example is a project merge request search with scope=merge_requests and search=%20. The Sentry issue is GITLABCOM-FJD9.
The fix is in the query builder, not a nil guard in add_filter. A guard would hide the mismatch, and the builder is the part that is inconsistent.
Why this started failing
- Merge request search at project and group level also searches comments. It reaches note search through
related_ids_for_notes. - Before commit 4a7b0c10 ("Use optimized auth in note ES query", 2025-07-24), note search used
project_ids_filter. That method didfilter ||= [], which hid the missing array. - The commit moved note search to a path that assumes the array exists, so blank queries started to fail.
Test coverage
I added a spec in ee/spec/lib/elastic/latest/note_class_proxy_spec.rb, "when the query is blank", at project level. It fails with NoMethodError without the fix.
References
- Closes #633013 (closed)
Screenshots or screen recordings
Request: GET /api/v4/projects/1/search?scope=merge_requests&state=opened&search=%20
| Before | After |
|---|---|
![]() |
![]() |
Before, the request returns 500 Internal Server Error. After, it returns the merge request JSON.
How to set up and validate locally
- Use a GDK with Advanced Search enabled. In Admin > Settings > Search, turn on "Search with Advanced Search" and finish indexing.
- Sign in.
- Open
https://gdk.test:3443/api/v4/projects/<id>/search?scope=merge_requests&state=opened&search=%20for a project that has open merge requests. - On
master, the response is a 500 error. On this branch, it is JSON results.
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.

