2012-10-09 173 views
6

我有一臺ElasticSearch服務器運行該索引並使用優秀的Tire gem搜索文檔。一切都很好,除了我不確定如何從搜索索引中手動刪除文檔。使用Tire刪除/刪除ElasticSearch中的索引文檔(使用ActsAsParanoid軟刪除)

我已經倒了RDoc並搜索了幾個小時,但這是我能找到的解決方案的唯一暗示https://github.com/karmi/tire/issues/309。除了圍繞curl構建自定義包裝並手動提出請求外,是否還有更簡單的方法?

另一個問題是我使用了一個名爲ActsAsParanoid的軟刪除gem,所以Tire :: Model :: Callbacks不會刪除軟刪除對象。

任何想法?

回答

6

原來你可以手動從索引中移除軟刪除的對象,像這樣:

@user = User.find(id) #or whatever your indexed object is 
User.tire.index.remove @user #this will remove them from the index 

完蛋了!

10

如果你只有ID(如12345):

User.tire.index.remove 'user', '12345' 

或者更一般地說:

klass.tire.index.remove klass.document_type, record_id 

(我認爲這是相當於什麼remove @user將在幕後做)

reference