I've configured Elasticsearch in my Rails application API and for Post model, it's working properly and I'm using @post.destroy!
to delete a specific record without any problem, but when I'm trying the same through Activeadmin panel destroy action (I tried default destroy action and custom controller -> destroy action ), here what's happening is deleting the record properly from db but after deleting it throws an exception :
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}}
I've tried all custom callbacks which mentioned in elasticsearch-model documentation but the only one solution I found is by using begin .. rescue
statement:
@deleted = false
begin
@post.destroy!
rescue
Post.find_by(:id => id).present? ? @deleted = false : @deleted = true
#delete successful action here if @deleted == true
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.