Class: Workarea::UpdateElasticsearchSettings

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/update_elasticsearch_settings.rb

Instance Method Summary collapse

Instance Method Details

#perform(settings) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/workers/workarea/update_elasticsearch_settings.rb', line 6

def perform(settings)
  Elasticsearch::Document.all.each do |klass|
    klass.current_index.wait_for_health # For initial setup

    klass.current_index.while_closed do
      # number_of_shards cannot be updated, ES will return
      # a 400 error
      Workarea.elasticsearch.indices.put_settings(
        index: klass.current_index.name,
        body: {
          settings: settings.except(
            'number_of_shards',
            'number_of_replicas'
          )
        }
      )
    end

    klass.current_index.wait_for_health # For running inline (e.g. tests)
  end
end