简体   繁体   English

当我停止Rails服务器时,我的Elasticsearch索引会怎样?

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

I am very new to using Elasticsearch in a Rails application and am using the chewy gem to implement it. 我对在Rails应用程序中使用Elasticsearch非常陌生,并且正在使用耐嚼的gem来实现它。 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. 当我通过rails s在开发模式下运行Rails应用程序时,我随后通过elasticsearch命令运行Elasticsearch并运行rake chewy:reset:all为我的数据创建一个索引。

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. 一切工作正常,但如果重新启动服务器,则必须再次运行rake chewy:reset:all命令来重建索引,否则会出现错误。 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. 我对Elasticsearch的功能不是很熟悉,所以希望有人对幕后发生的事情有所了解的人会感到感激。

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. 我从未使用过Chewy,但是从他们的文档来看,如果您将config / initializers / chewy.rb中的“ Chewy.settings = {prefix:'test'}”放进去,它将在开发过程中以“ test”作为前缀。 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 ). 还请注意,黄瓜倾向于在开发模式下运行测试( 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: 因此,请尝试从您的代码中删除“ Chewy.settings = {prefix:'test'}”,而应将这样的内容放入您的chewy.yml文件中:

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

And then add this to your cucumber env.rb file: 然后将其添加到您的黄瓜env.rb文件中:

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

And try running cucumber again with rake cucumber 并尝试用耙子黄瓜再次运行黄瓜

When you run elasticsearch in your terminal, think of it as a separate server, just like your rails s . 在终端中运行elasticsearch ,将其视为独立的服务器,就像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. 如果Chewy的索引文档在数据库中没有匹配记录,则可能会出现一些意外错误。 According to Chewy's README : 根据Chewy的自述文件

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. 最好在测试套件中设置:bypass策略并仅在需要时手动导入对象,并在需要时使用Chewy.massacre在每个示例之前刷新测试ES索引。 This will allow you to minimize unnecessary ES requests and reduce overhead. 这将使您最大程度地减少不必要的ES请求并减少开销。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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