简体   繁体   English

使用Tire有条件索引文档进行Elasticsearch

[英]Conditionally index document for elasticsearch using Tire

I'm using tire with rails and elasticsearch. 我正在使用带导轨和elasticsearch的轮胎 I want to conditionally add a document to the index if a boolean flag on my model is true. 如果模型上的布尔标志为true,我想有条件地将文档添加到索引。 I'm sure this is straight forward but I can't seem to find out how to. 我敢肯定这是直截​​了当的,但我似乎找不到办法。

I worked out solution. 我制定了解决方案。 I removed this callback include from my model: 我从模型中删除了此回调包含:

include Tire::Model::Callbacks

and implemented my own callback like this: 并实现了我自己的回调,如下所示:

after_save do
  if live == true
    self.index.store self
  else
    self.index.remove self
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM