gpt4 book ai didi

ruby-on-rails - 当我执行update_all()时,Tire(elasticsearch)没有更新

转载 作者:行者123 更新时间:2023-12-02 23:06:29 25 4
gpt4 key购买 nike

我正在使用 ruby 在 rails 上与ElastiSearch连接。

当我使用update_attributes修改元素的参数时,Tire会自动更新索引以反射(reflect)此更改。

但是,当我通过执行update_all同时修改许多元素时,Tire不会更新索引,并且它与我的数据库不同步。

这是Tyre中的错误吗?有解决方法吗?

最佳答案

根据ActiveRecord#update_all documentation:

Updates all records with details given if they match a set of conditions supplied, limits and order can also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the database. It does not instantiate the involved models and it does not trigger Active Record callbacks.



所以Tire不更新任何内容,因为未调用回调。

您必须:

a)使用 find_each并调用 save方法

b)使用 update_all,但是要进行完整的重新索引。

关于ruby-on-rails - 当我执行update_all()时,Tire(elasticsearch)没有更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8797992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com