Advanced search - add support for label names
Description
Labels are currently stored as label_ids in Elasticsearch. This requires a database lookup when label_name parameter is provided in searches. For large instances, global search doesn't perform well and the query may timeout.
We also need label_names field to perform wildcard matches for GLQL. For example, GLQL supports this syntax for labels label != ~"workflow::*".
Proposal
Switch the work items index to also index label_names. The names can be used for searches while the label_ids existing can be used to update data when changes are made to the label record.
1. Follow the guide to add a new field to the work item index:
* field:
label_names* type: keyword
- Create a new search filter called
by_label_names.
- A
termsquery in combination withboolquery can allow=/into be served bylabel_namesparam and!=to be served bynot_label_names - It must support
=,in,!=operations to mimic GLQL as well as the supported input types - It also should support the wildcard match when we only want to filter out label names by a partial match, for example,
label = ~"workflow::*"should match all labels starting withworkflow::such as workflowcomplete or workflowin dev.
-
Change the work item query builder to use the new filter.
-
Explicitly allow new
label_names(might be already allowed, needs to be double checked) andnot_label_namesfilters to be passed down toWorkItemQueryBuilder:
- Add a two new params called
label_names(might be already allowed, needs to be double checked) andnot_label_namesto the filters inEE::Search::Filter concernand inee/lib/gitlab/elastic/search_results.rb.
- Add documentation about the new filter to the list of available filters
Note: the existing by_label_ids filter is also used by merge requests so it can't be modified.