URI::InvalidURIError: the scheme http does not accept registry part: :9200 (or bad hostname?)

荒凉一梦 提交于 2019-12-11 01:38:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!