简体   繁体   中英

Searchbox Elasticsearch Heroku No Results

I have a production app on heroku, with the searchbox addon.

In my controller I have:

 # GET /venues
  # GET /venues.json
  def index
    @supplier = Supplier.find(current_user.profileable_id)
    @venues = @supplier.venues
  end

And in my model:

 include Tire::Model::Search
  include Tire::Model::Callbacks
  index_name("#{Rails.env}")

In my production environment.rb:

 # Elastic search - Searchbox
  ENV['ELASTICSEARCH_URL'] = ENV['SEARCHBOX_URL']

According to the documentation, that should be all I need. However, the addon is not automatically creating the index or mapping. Without either, heroku logs show a 400 error indicating no index, which it should. If I add an index with the name 'production' (based on the #{Rails.env} above) then it doesn't throw any errors, but there are no search results. If I then ask Saerchbox to do a crawl of the sites URL, it does some mapping, but is not correct (I know this as we have another instance of the app running elsewhere on heroku, with the same settings and it works fine ie create it's own index and mapping).

What am I missing? Do I need a heroku run command that i've missed somewhere to create the index?

Ok, worked it out. I needed to run this rake:

heroku run rake environment tire:import CLASS=Venue FORCE=true

In this case Venue was the model I was indexing, so swap it out for your model when using this.

Whilst tire creates indicies automatically in development, it won't in production so you have to force it with a rake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM