【问题标题】:Remove/Delete an indexed document in ElasticSearch with Tire (with soft delete via ActsAsParanoid)使用 Tire 删除/删除 ElasticSearch 中的索引文档(通过 ActsAsParanoid 软删除)
【发布时间】:2012-10-09 14:28:04
【问题描述】:

我有一个 ElasticSearch 服务器正在运行,它使用出色的 Tire gem 来索引和搜索文档。一切都很好,除了我不确定如何从搜索索引中手动删除文档。

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

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

有什么想法吗?

【问题讨论】:

    标签: elasticsearch tire


    【解决方案1】:

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

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

    或更笼统地说:

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

    (我认为这相当于remove @user 在幕后所做的)

    reference

    【讨论】:

      【解决方案2】:

      原来你可以像这样从索引中手动删除软删除的对象:

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

      就是这样!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-17
        • 2016-08-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多