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

The above part is going to be implemented as a part of this issue #540792 (closed)

  1. Create a new search filter called by_label_names.
  • A terms query in combination with bool query can allow =/in to be served by label_names param and != to be served by not_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 with workflow:: such as workflowcomplete or workflowin dev.
  1. Change the work item query builder to use the new filter.

  2. Explicitly allow new label_names (might be already allowed, needs to be double checked) and not_label_names filters to be passed down to WorkItemQueryBuilder:

  1. 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.

Edited by 🤖 GitLab Bot 🤖