Elastic migration helper for creating a new index
What does this MR do and why?
Adds an Elastic migration helper for creating a new index: Elastic::MigrationCreateIndex
that can be called as follows:
class MigrationName < Elastic::Migration
include Elastic::MigrationCreateIndex
retry_on_failure
def document_type
:epic
end
def target_class
Epic
end
end
This will be used to create the Epic index.
How to set up and validate locally
Note: in order to test, you will need to delete an existing index (and loose the data).
- Delete the
user
index:Gitlab::Elastic::Helper.default.delete_index(index_name: 'gitlab-development-users')
Gitlab::Elastic::Helper.default.index_exists?(index_name: 'gitlab-development-users') => false
- Create a new migration:
touch ee/elastic/migrate/20230531135700_create_temp_user_index
- Add the following to the file:
class CreateTempUserIndex < Elastic::Migration include Elastic::MigrationCreateIndex retry_on_failure def document_type :user end def target_class User end end
- Execute the migration worker a few times:
Elastic::MigrationWorker.new.perform
Gitlab::Elastic::Helper.default.index_exists?(index_name: 'gitlab-development-users') => true
- Delete the temporary migration that was created.
- Reindex users:
bundle exec rake gitlab:elastic:index_users
Example logs
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #250699 (closed)
Edited by Madelein van Niekerk