I am very new to using Elasticsearch in a Rails application and am using the chewy gem to implement it. When I run my rails app in development mode via rails s
I then run Elasticsearch via the elasticsearch
command and run the rake chewy:reset:all
to create an index for my data.
Everything works fine doing this but if I restart the server I have to run the rake chewy:reset:all
command again to rebuild the index otherwise I get an error. What happens to the index when I restart the server? Is it destroyed when the server is stopped?
I am not very familiar with how Elasticsearch functions so would appreciate anyone shedding a little light on what is happening behind the scenes.
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.
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With