From dd049fc37aa7281d859625bdbcde2e9fa7a09224 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 14 Aug 2023 19:00:56 +0200 Subject: [PATCH] Fix ES_PRESET not being applied to Chewy's internal index (#26489) --- config/initializers/chewy.rb | 3 +++ lib/mastodon/cli/search.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/initializers/chewy.rb b/config/initializers/chewy.rb index 7d51a08457..66008a0009 100644 --- a/config/initializers/chewy.rb +++ b/config/initializers/chewy.rb @@ -15,6 +15,9 @@ Chewy.settings = { journal: false, user: user, password: password, + index: { + number_of_replicas: ['single_node_cluster', nil].include?(ENV['ES_PRESET'].presence) ? 0 : 1, + }, } # We use our own async strategy even outside the request-response diff --git a/lib/mastodon/cli/search.rb b/lib/mastodon/cli/search.rb index ee1c0fade1..41862b5b6b 100644 --- a/lib/mastodon/cli/search.rb +++ b/lib/mastodon/cli/search.rb @@ -18,6 +18,7 @@ module Mastodon::CLI option :only, type: :array, enum: %w(instances accounts tags statuses), desc: 'Only process these indices' option :import, type: :boolean, default: true, desc: 'Import data from the database to the index' option :clean, type: :boolean, default: true, desc: 'Remove outdated documents from the index' + option :reset_chewy, type: :boolean, default: false, desc: "Reset Chewy's internal index" desc 'deploy', 'Create or upgrade Elasticsearch indices and populate them' long_desc <<~LONG_DESC If Elasticsearch is empty, this command will create the necessary indices @@ -42,6 +43,8 @@ module Mastodon::CLI importers = indices.index_with { |index| "Importer::#{index.name}Importer".constantize.new(batch_size: options[:batch_size], executor: pool) } progress = ProgressBar.create(total: nil, format: '%t%c/%u |%b%i| %e (%r docs/s)', autofinish: false) + Chewy::Stash::Specification.reset! if options[:reset_chewy] + # First, ensure all indices are created and have the correct # structure, so that live data can already be written indices.select { |index| index.specification.changed? }.each do |index|