4

I have a searchable Item model in my Rails app.

I want to index the majority of those in ElasticSearch, EXCEPT the ones that fulfill some condition.

How can I do that?

Is overriding update_index in the model an acceptable solution?


I know I could also index them all, and filter them out in the search. But they will never be searchable so I don't see a reason for indexing them at all.

Robin
  • 21,667
  • 10
  • 62
  • 85

1 Answers1

7

The easiest thing is to handle the indexing hook yourself, as stated in the README:

Notice, that you may want to skip including the Tire::Model::Callbacks module in special cases, like when your records are indexed via some external mechanism (...) or when you need better control on how the documents are added to or removed from the index:

class Article < ActiveRecord::Base
  include Tire::Model::Search

  after_save do
    update_index if state == 'published'
  end
end
karmi
  • 14,059
  • 3
  • 33
  • 41
  • Thanks Karmi. Actually someone answered and pointed me to a github thread where you discussed this issue, but he deleted his answer I guess. – Robin Mar 02 '13 at 16:00