Advanced search - Allow sorting work items by title

Description

When trying to sort work items by their title via ES, you get the following error:

Elasticsearch::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":
[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on [title] in 
[gitlab-development-work_items-20250603-1019]. Text fields are not optimised for operations 
that require per-document field data like aggregations and sorting, so these operations 
are disabled by default. Please use a keyword field instead. 
Alternatively, set fielddata=true on [title] in order to load field data by 
uninverting the inverted index. Note that this can use significant memory."}]

My proposal is to add keyword type for the title alongside with the existing text type in ee/lib/search/elastic/types/work_item.rb

title: { type: 'text', index_options: 'positions', analyzer: :title_analyzer,  fields: { keyword: { type: 'keyword' } } }

❗ Please see this discussion thread about the impact on data and storage if we decided to add extra field for the title #562593 (comment 2698211747).

Implementation

  1. Please refer to this issue description for the steps on how to add new mapping and backfill data in ES #540799
  2. After the data is migrated, we'll have to allow title_desc and title_asc in AdvancedFinders::WorkItemsFinder in SORT_KEYS.
  3. Then we'll need to update mappings in ee/lib/search/elastic/sorts.rb and lib/gitlab/search/sort_options.rb.
Edited by 🤖 GitLab Bot 🤖