Skip to content

Instantly share code, notes, and snippets.

@diegoy
Last active April 12, 2018 21:22
Show Gist options
  • Save diegoy/1c0e93adcfcd559faaba823a5bf3c7eb to your computer and use it in GitHub Desktop.
Save diegoy/1c0e93adcfcd559faaba823a5bf3c7eb to your computer and use it in GitHub Desktop.
# config/initializer/elasticsearch.rb
config = {
transport_options: { request: { timeout: 5 } }
}
if File.exist?('config/elasticsearch.yml')
template = ERB.new(File.new('config/elasticsearch.yml').read)
processed = YAML.safe_load(template.result(binding))
config.merge!(processed[Rails.env].symbolize_keys)
end
# if you choose to use elasticsearch-rails-model
Elasticsearch::Model.client = Elasticsearch::Client.new(config)
# if you choose to use elasticsearch-rails-persistence
Elasticsearch::Persistence.client = Elasticsearch::Client.new(config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment