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!