module Elastic::Railties::Utils
Public Instance Methods
cleanup()
click to toggle source
# File lib/elastic/railties/utils.rb, line 31 def cleanup logger.info "Searching for orphan indices" indices.each { |index| index.connector.remove_orphaned_indices } end
drop(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 36 def drop(_index = nil) logger.info "Dropping all indices" if _index.nil? indices(_index).each &:drop end
migrate(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 23 def migrate(_index = nil) logger.info "Migrating all indices" if _index.nil? indices(_index).each do |index| logger.info "Migrating index #{index.suffix}" handle_errors { index.migrate } end end
reindex(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 3 def reindex(_index = nil) logger.info "Reindexing all indices" if _index.nil? indices(_index).each do |index| logger.info "Reindexing index #{index.suffix}" handle_errors { index.reindex } end end
remap(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 11 def remap(_index = nil) logger.info "Remapping all indices" if _index.nil? indices(_index).each do |index| logger.info "Remapping index #{index.suffix}" handle_errors do unless index.connector.remap logger.info 'Mapping couldnt be changed, make sure you call migrate' end end end end
stats(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 41 def stats(_index = nil) logger.info "Indices stats" if _index.nil? indices(_index).each do |index| logger.info "Stats for #{index.suffix}:" # TODO. end end
Private Instance Methods
handle_errors() { || ... }
click to toggle source
# File lib/elastic/railties/utils.rb, line 68 def handle_errors yield rescue => exc logger.error exc.message logger.error exc.backtrace.join("\n") end
indices(_index = nil)
click to toggle source
# File lib/elastic/railties/utils.rb, line 51 def indices(_index = nil) Dir.glob(indices_paths.join('**/*.rb')).map do |path| path = Pathname.new path path = path.relative_path_from indices_paths path = path.dirname.join(path.basename(path.extname)).to_s next nil if _index && (path != _index && path.camelize != _index) klass = path.camelize.constantize next nil unless klass < Elastic::Type klass end.reject(&:nil?) end
indices_paths()
click to toggle source
# File lib/elastic/railties/utils.rb, line 64 def indices_paths Rails.root.join(Elastic.config.indices_path) end
logger()
click to toggle source
# File lib/elastic/railties/utils.rb, line 75 def logger Elastic.logger end