我已经在我的Rails应用程序API和Post模型中配置了Elasticsearch,它正常工作,我正在使用@post.destroy!
删除特定记录而没有任何问题,但当我通过Activeadmin尝试相同时面板销毁动作(我试过默认销毁动作和自定义控制器 - >销毁动作),这里发生的事情是从数据库中正确删除记录但是在删除它之后抛出异常:
Elasticsearch::Transport::Transport::Errors::NotFound in Admin::PostsController#destroy
[404] {"found":false,"_index":"posts","_type":"post","_id":"1802","_version":1,"_shards":{"total":2,"successful":1,"failed":0}}
答案 0 :(得分:0)
我已经尝试了elasticsearch-model documentation中提到的所有自定义回调,但我找到的唯一解决方案是使用begin .. rescue
语句:
@deleted = false
begin
@post.destroy!
rescue
Post.find_by(:id => id).present? ? @deleted = false : @deleted = true
#delete successful action here if @deleted == true
end