简体   繁体   中英

Delta indexing the elastic search index on change of model's association record value change using Tire and Elastic Search

I am a newbie to elastic Search and Tire in Ruby on Rails. Watched the railscasts from ryan bates and helped me to get going. Tire is a great gem and has functionality to delta indexing. Assuming i have a mapping like the following, will Tire automatically delta index the model associations if an association value is edited/ deleted. For Example, Assume i have index mapping like the following,

 mapping do
    indexes :id,      :type => 'integer', :index    => :not_analyzed
    indexes :col_2,   :type => 'integer', :index    => :not_analyzed
    indexes :col_3,   :type => 'date'
    indexes :col_4,   :type => 'date'

    indexes :model_2 do
      indexes :name,                  :type => 'string', :analyzer => 'whitespace'
      indexes :association_col_2,     :type => 'string', :index    => :not_analyzed
    end
 end

When the value of model_2.association_col_2 changes will tire automatically delta index the corresponding row in the model defined the mapping for ? How should i approach delta indexing the model on association model value changes ?

Thanks in advance

Tire is different to eg. Thinking Sphinx, because no delta indexing is actually happening: when your model changes, and you have included the indexing callbacks, the whole record serialized to JSON is sent down the wire to elasticsearch, replacing older document (keep in mind elasticsearch is actually a “searchable document database”).

If you want to trigger the callback in the parent model from the child model, you have to instrument Rails for doing so:

class Brake < ActiveRecord::Base
  belongs_to :car, :touch => true
end

See the documentation for the ActiveRecord#touch method. You'll have to add a subscriber in your parent model as well, though, as documented in this StackOverflow answer: Elasticsearch, Tire, and Nested queries / associations with ActiveRecord .

Of course, you can also take care of that manually, triggering updates via observers, using background processing / messaging, etc.

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