GitLab Advanced Search initial indexing using OpenSearch 2.18.0 does not work (space type cosinesimil not supported)

Summary

Customer is using GitLab Advanced Search together with OpenSearch 2.18.0.

Today we found out that our search index was not up to date anymore. Our final solution was to recreate the indexes and start from scratch.

Unfortunately this did not work and now they couldn't use GitLab Advanced Search at all until they downgraded to 2.17.1.

It looks like GitLab is trying to use an invalid configuration combination, seen in the following output of gitlab-rake gitlab:elastic:recreate_index

Index/alias 'gitlab-production' was not found
Index 'gitlab-production-issues' with alias 'gitlab-production-issues' was not found
Index 'gitlab-production-notes' with alias 'gitlab-production-notes' was not found
Index 'gitlab-production-merge_requests' with alias 'gitlab-production-merge_requests' was not found
Index 'gitlab-production-commits' with alias 'gitlab-production-commits' was not found
Index 'gitlab-production-epics' with alias 'gitlab-production-epics' was not found
Index 'gitlab-production-users' with alias 'gitlab-production-users' was not found
Index 'gitlab-production-wikis' with alias 'gitlab-production-wikis' was not found
Index 'gitlab-production-projects' with alias 'gitlab-production-projects' was not found
Index 'gitlab-production-work_items' with alias 'gitlab-production-work_items' was not found
Index/alias 'gitlab-production-migrations' was not found
rake aborted!
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Validation Failed: 1: \"hnsw\" with \"faiss\" configuration does not support space type: \"cosinesimil\".;"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Validation Failed: 1: \"hnsw\" with \"faiss\" configuration does not support space type: \"cosinesimil\".;","caused_by":{"type":"validation_exception","reason":"Validation Failed: 1: \"hnsw\" with \"faiss\" configuration does not support space type: \"cosinesimil\".;"}},"status":400}
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/elastic/helper.rb:457:in `create_index'
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/elastic/helper.rb:166:in `block in create_standalone_indices'
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/elastic/helper.rb:162:in `each'
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/elastic/helper.rb:162:in `each_with_object'
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/gitlab/elastic/helper.rb:162:in `create_standalone_indices'
/opt/gitlab/embedded/service/gitlab-rails/ee/app/services/search/rake_task_executor_service.rb:71:in `create_empty_index'
/opt/gitlab/embedded/service/gitlab-rails/ee/app/services/search/rake_task_executor_service.rb:110:in `recreate_index'
/opt/gitlab/embedded/service/gitlab-rails/ee/app/services/search/rake_task_executor_service.rb:48:in `execute'
/opt/gitlab/embedded/service/gitlab-rails/ee/lib/tasks/gitlab/elastic.rake:90:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:25:in `load'
/opt/gitlab/embedded/bin/bundle:25:in `<main>'
Tasks: TOP => gitlab:elastic:recreate_index
(See full trace by running task with --trace)

The 400 BadRequest from OpenSearch 2.18.0 shows an validation error which says that the space type “cosinesimil” is not to be used with “hnsw with faiss”.

The following already merged into the 17.5 code base seems to be relevant:

!163009 (diffs)

Steps to reproduce

  1. Install GitLab 17.5.3.
  2. Setup an OpenSearch cluster on 2.18.0 via the instructions on OpenSearch's site.
  3. Configure GitLab's Advanced Search to use the OpenSearch 2.18.0 cluster and attempt to index.

What is the current bug behavior?

When attempting to reindex with gitlab-rake gitlab:elastic:recreate_index, an error is thrown indicating that GitLab is trying to use an invalid configuration combination.

What is the expected correct behavior?

OpenSearch should work with version 2.18.0 if it's compatible with 1.x or later.

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

gitlab-rake gitlab:env:info

System information
System:        Ubuntu 22.04
Proxy:        no
Current User:    git
Using RVM:    no
Ruby Version:    3.2.5
Gem Version:    3.5.17
Bundler Version:2.5.11
Rake Version:    13.0.6
Redis Version:    7.0.15
Sidekiq Version:7.2.4
Go Version:    unknown
GitLab information
Version:    17.5.3-ee
Revision:    9d81c27eee7
Directory:    /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:    PostgreSQL
DB Version:    14.11
URL:        https://git.group.com
HTTP Clone URL:    https:///some-group/some-project.git
SSH Clone URL:    git@git.:some-group/some-project.git
Elasticsearch:    yes
Geo:        yes
Geo node:    Primary
Using LDAP:    yes
Using Omniauth:    yes
Omniauth Providers:
GitLab Shell
Version:    14.39.0
Repository storages:
- default:     unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path:        /opt/gitlab/embedded/service/gitlab-shell
Gitaly
- default Address:     unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version:     17.5.3
- default Git Version:     2.46.2

Results of GitLab application Check

Possible fixes

Looks like version 2.18.0 of OpenSearch uses FAISS as the default:

https://github.com/opensearch-project/opensearch-build/blob/main/release-notes/opensearch-release-notes-2.18.0.md https://github.com/opensearch-project/k-NN/pull/2221).

Edited by Gabriel Yoachum