Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Searchkick在测试时手动重新索引关联_Ruby On Rails_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Searchkick - Fatal编程技术网 elasticsearch,searchkick,Ruby On Rails,elasticsearch,Searchkick" /> elasticsearch,searchkick,Ruby On Rails,elasticsearch,Searchkick" />

Ruby on rails Searchkick在测试时手动重新索引关联

Ruby on rails Searchkick在测试时手动重新索引关联,ruby-on-rails,elasticsearch,searchkick,Ruby On Rails,elasticsearch,Searchkick,我正在手动调用关联上的重新索引,以便它们按照 然而,在我的测试环境中,reindex调用抛出了一个错误。在CI上,错误是可以理解的端口9200没有运行,因为ES没有运行。在本地,错误看起来更像这样,表明文档不存在 我有指定的Searchkick.disable\u callbacks在我的test\u助手中 设置: class Parent < ApplicationRecord belongs_to :client searchkick def search_data

我正在手动调用关联上的重新索引,以便它们按照

然而,在我的测试环境中,reindex调用抛出了一个错误。在CI上,错误是可以理解的端口9200没有运行,因为ES没有运行。在本地,错误看起来更像这样,表明文档不存在

我有指定的
Searchkick.disable\u callbacks
在我的test\u助手中

设置:

class Parent < ApplicationRecord
  belongs_to :client

  searchkick

  def search_data
    { name }.merge(**client_data)
  end

  def client_data
    { market_id: client.market_id }
  end
end

class Client < ApplicationRecord
  has_many :parents

  after_save :reindex_parents

  def reindex_parents
    parents.reindex(:client_data) # <-- ERROR raised here without `unless Rails.env.test?` guard
  end
end
我可以通过使用
除非Rails.env.test?
保护
reindex\u parents
调用来避免这个问题,但似乎应该有更好的方法

我错过什么了吗?
有什么想法吗?

由于已禁用回调,搜索索引将不包含任何数据。当
reindex\u parents
尝试更新不存在的文档时,将抛出一个错误。除非Rails.env.test?,否则如果Searchkick.callbacks?感觉更干净,可以使用

TestClass#test_name:
Searchkick::ImportError: {"type"=>"document_missing_exception", "reason"=>"[model][395824130]: document missing", "index_uuid"=>"5UOKtvfvR52x76Nf5njMBQ", "shard"=>"0", "index"=>"students_test"} on item with id '395824130' ....