【发布时间】:2018-08-09 16:42:23
【问题描述】:
我正在手动调用关联的重新索引,以便它们按照docs 的规定保持最新。
但是,在我的测试环境中,重新索引调用会引发错误。在 CI 上,错误是一个可以理解的端口 9200 没有运行,因为 ES 没有运行。在本地,错误看起来更像这样,表明文档不存在。
我的 test_helper 中有规定的 Searchkick.disable_callbacks
设置:
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
错误:
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' ....
我可以通过使用unless Rails.env.test? 保护reindex_parents 调用来避免此问题,但似乎应该有更好的方法
我错过了什么吗? 有什么想法吗?
【问题讨论】:
标签: ruby-on-rails elasticsearch searchkick