What happens to my elasticsearch index when I stop rails server? What happens to my elasticsearch index when I stop rails server? elasticsearch elasticsearch

What happens to my elasticsearch index when I stop rails server?


When you run elasticsearch in your terminal, think of it as a separate server, just like your rails s. It runs completely independent from your application server. Being a Chewy user myself, I think you're dealing with polluted indexes. Here's how to troubleshoot:

Check that you are updating the index when you add/delete records to the database. If Chewy has an indexed document that has no matching record in your database, you can get some unexpected errors. According to Chewy's README:

It is also a good idea to set up the :bypass strategy inside your test suite and import objects manually only when needed, and use Chewy.massacre when needed to flush test ES indices before every example. This will allow you to minimize unnecessary ES requests and reduce overhead.

RSpec.configure do |config|  config.before(:suite) do    Chewy.strategy(:bypass) # if you're not using RSpec, copy this line and paste it in the setup script of your suite.  endend


I have never used Chewy, but judging by their docs if you put "Chewy.settings = {prefix: 'test'}" in config/initializers/chewy.rb it will prefix everything with 'test', also in development. I don't know if that is where you put it, of course.

Note also that cucumber has a tendency to run your tests in development mode (https://github.com/cucumber/cucumber-rails/issues/222).

Therefore, try removing the "Chewy.settings = {prefix: 'test'}" from your code, and instead put something like this in your chewy.yml file:

# config/chewy.ymlcucumber:  host: 'localhost:9200'  prefix: 'test'

And then add this to your cucumber env.rb file:

ENV["RAILS_ENV"] ||= 'cucumber'

And try running cucumber again with rake cucumber