问题
I am using Elasticsearch / SearchKick / Bonsai to set up search in production on Heroku. This is working beautifully locally, but I am having trouble indexing my objects on Heroku.
in config/initializers/bonsai.rb
require 'elasticsearch/model'
if ENV['BONSAI_URL']
Elasticsearch::Model.client = Elasticsearch::Client.new({url: ENV['BONSAI_URL'], logs: true})
end
in lib/tasks/elasticsearch.rb
require 'elasticsearch/rails/tasks/import'
in user.rb
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
searchkick
def search_data
attributes.merge(
profile_name: profile.name(&:name),
book_title: books.map(&:title)
)
end
gemfile
gem 'bonsai-elasticsearch-rails' #in the production group
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem "searchkick"
I ran: heroku config:add BONSAI_URL=mybonsaiurl
But, when I try to reindex with: heroku run rake searchkick:reindex CLASS=User I get: URI::InvalidURIError: the scheme http does not accept registry part: :9200 (or bad hostname?)
Or when I do: User.elasticsearch.create_index! force: true I get: User.elasticsearch.create_index!: command not found
It seems like SearchKick or something is set to 9200 by default but I am not sure how to change it or whether it should look for my app URL or the Bonsai URL -- I am really lost and seem to have missed a step somewhere?
Thanks for any help!
回答1:
Solved thanks to Heroku support team.
I was trying to use two different clients - the official Elasticsearch rails client, and Searchkick. I went thru and removed all the configuration for the 3 Elasticsearch/Bonsai gems, and edited this file:
config/initializers/bonsai.rb
if ENV['BONSAI_URL']
# Elasticsearch::Model.client = Elasticsearch::Client.new({url: ENV['BONSAI_URL'], logs: true})
Searchkick.client = Elasticsearch::Client.new({url: ENV[‘BONSAI_URL’], logs: true})
end
Now, I can run: heroku run rake searchkick:reindex:all to index my models.
More here: http://danifankhauser.com/post/104137889438/rails-how-to-index-searchkick-on-heroku-with
来源:https://stackoverflow.com/questions/27181741/uriinvalidurierror-the-scheme-http-does-not-accept-registry-part-9200-or-b