Skip to content

Elastic migration helper for creating a new index

Madelein van Niekerk requested to merge 250699-create-index-helper into master

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

  1. Delete the user index: Gitlab::Elastic::Helper.default.delete_index(index_name: 'gitlab-development-users')
  2. Gitlab::Elastic::Helper.default.index_exists?(index_name: 'gitlab-development-users') => false
  3. Create a new migration: touch ee/elastic/migrate/20230531135700_create_temp_user_index
  4. 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
  5. Execute the migration worker a few times: Elastic::MigrationWorker.new.perform
  6. Gitlab::Elastic::Helper.default.index_exists?(index_name: 'gitlab-development-users') => true
  7. Delete the temporary migration that was created.
  8. Reindex users: bundle exec rake gitlab:elastic:index_users

Example logs

Screenshot_2023-05-31_at_14.17.24

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #250699 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading