Autocomplete: Change user authorization to use terms query for projects
What does this MR do and why?
Update the Elasticsearch query used for filtering users during autocomplete to prevent too_many_clauses
errors as reported in #534033 (closed). This is seen when the current user has many authorized groups or projects.
The change combines all the ids for authorized projects into one terms
query instead of having one prefix
query per project, thereby reducing the number of clauses.
Before
{:query=>
{:bool=>
{:must=>[{:simple_query_string=>{:_name=>"user:match:search_terms", :fields=>["name", "username", "public_email"], :query=>"maddiev~", :lenient=>true, :default_operator=>:and}}],
:should=>[],
:filter=>
[{:term=>{:type=>{:_name=>"doc:is_a:user", :value=>"user"}}},
{:term=>{:in_forbidden_state=>{:value=>false, :_name=>"filter:not_forbidden_state"}}},
{:bool=>
{:should=>
[{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>22}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>24}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>27}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>29}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>"1-p15-"}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>"31-p6-"}}}],
:minimum_should_match=>1}}]}},
:highlight=>{:fields=>{:name=>{}, :username=>{}, :public_email=>{}}, :number_of_fragments=>0, :pre_tags=>["gitlabelasticsearch→"], :post_tags=>["←gitlabelasticsearch"]}}
After
{:query=>
{:bool=>
{:must=>[{:simple_query_string=>{:_name=>"user:match:search_terms", :fields=>["name", "username", "public_email"], :query=>"maddiev~", :lenient=>true, :default_operator=>:and}}],
:should=>[],
:filter=>
[{:term=>{:type=>{:_name=>"doc:is_a:user", :value=>"user"}}},
{:term=>{:in_forbidden_state=>{:value=>false, :_name=>"filter:not_forbidden_state"}}},
{:bool=>
{:minimum_should_match=>1,
:should=>
[{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>22}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>24}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>27}}},
{:prefix=>{:namespace_ancestry_ids=>{:_name=>"namespace:ancestry_filter:descendants", :value=>29}}},
{:terms=>{:namespace_ancestry_ids=>["1-p15-", "31-p6-"], :_name=>"namespace:ancestry_filter:project_ids"}}]}}]}},
:highlight=>{:fields=>{:name=>{}, :username=>{}, :public_email=>{}}, :number_of_fragments=>0, :pre_tags=>["gitlabelasticsearch→"], :post_tags=>["←gitlabelasticsearch"]}}
References
Advanced Search: more efficient user search (#534033 - closed)
How to set up and validate locally
- Perform autocomplete queries on master vs. on this branch and make sure the behaviour is the same.
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.
Related to #534033 (closed)