Activeadmin在管理员[404]中使用异常Elasticsearch :: Transport :: Transport :: Errors :: NotFound销毁记录

时间:2016-09-28 11:37:06

标签: ruby-on-rails elasticsearch

我已经在我的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}}

1 个答案:

答案 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