删除/删除ElasticSearch with Tire中的索引文档(通过ActsAsParanoid进行软删除)

tho*_*nch 6 elasticsearch tire

我有一个ElasticSearch服务器运行,使用优秀的Tire gem索引和搜索文档.一切都很好,除了我不知道如何手动从搜索索引中删除文档.

我已经倾倒了RDoc并搜索了几个小时,但这是解决方案的唯一提示我可以找到https://github.com/karmi/tire/issues/309.除了在curl周围构建自定义包装器并手动发出请求之外,还有更简单的方法吗?

另一个问题是我使用了名为ActsAsParanoid的软删除gem,因此Tire :: Model :: Callbacks不会删除软删除对象.

有任何想法吗?

mah*_*off 10

如果您只有ID(例如12345):

User.tire.index.remove 'user', '12345'
Run Code Online (Sandbox Code Playgroud)

或者更一般地说:

klass.tire.index.remove klass.document_type, record_id
Run Code Online (Sandbox Code Playgroud)

(我认为这相当于remove @user在幕后会做什么)

参考


tho*_*nch 6

事实证明你可以手动从索引中删除软删除的对象,如下所示:

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

而已!