Searchkick not returning any results in RSpec Searchkick not returning any results in RSpec elasticsearch elasticsearch

Searchkick not returning any results in RSpec


Try getting rid of all of that fancy stuff you are doing in your before(:suite) and your factories. You just need to be doing it before each spec (if the search tag is set).

I was able to get searchkick working with rspec and indexing my models with only this small amount of code in my spec_helper.rb:

RSpec.configure do |config|   config.before(:each) do |example|      # Elasticsearch / Searchkick      if example.metadata[:search]         Searchkick.enable_callbacks         Restaurant.reindex      else         Searchkick.disable_callbacks      end   endend

Side note: You may still need to run the Restaurant.search_index.refresh code after creating a bunch of Restaurant records in your spec setup. I'm not entirely sure?