Class: Octo::Setup::Create
- Inherits:
-
Object
- Object
- Octo::Setup::Create
- Defined in:
- lib/octocore-mongo/search/setup.rb
Overview
Creates the necessary indices
Class Method Summary collapse
Class Method Details
.perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/octocore-mongo/search/setup.rb', line 9 def self.perform sclient = Octo::Search::Client.new sconfig = Octo.get_config(:search) # Set the cluster disk space thresholds first. That's necessary # because the defaults are too less for development machines. So, # in order to keep it moving, we set a lower threshold in development. # Refer # https://www.elastic.co/guide/en/elasticsearch/reference/current/disk-allocator.html if sconfig.has_key?(:disk_threshold_low) and sconfig.has_key?(:disk_threshold_high) cluster_settings = { body: { persistent: { 'cluster.routing.allocation.disk.threshold_enabled' => true, 'cluster.routing.allocation.disk.watermark.low' => sconfig[:disk_threshold_low], 'cluster.routing.allocation.disk.watermark.high' => sconfig[:disk_threshold_high], 'cluster.info.update.interval' => '60s' } } } sclient.cluster.put_settings cluster_settings end # Check if any indices specified exists. If not exists, create them sconfig[:index].keys.each do |index_name| args = { index: index_name } if sclient.indices.exists?(args) Octo.logger.info "Search Index: #{ index_name } exists." else Octo.logger.warn "Search Index: #{ index_name } DOES NOT EXIST." Octo.logger.info "Creating Index: #{ index_name }" create_args = { index: index_name, body: sconfig[:index][index_name] } sclient.indices.create create_args end end # Also check if there are any indices present that should not be # present _indices = JSON.parse(sclient.cluster.state)['metadata']['indices']. keys.map(&:to_sym) extra_indices = _indices - sconfig[:index].keys Octo.logger.warn "Found extra indices: #{ extra_indices }" end |