简体   繁体   中英

Conditionally index document for elasticsearch using Tire

I'm using tire with rails and elasticsearch. I want to conditionally add a document to the index if a boolean flag on my model is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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