How could I keep the synchronization within elasticsearch-rails

589 Views Asked by At

I have a existing data in mysql.

I imported all records from mysql into elasticsearch with a rake task

However, I wonder know how could I keep synchronization when I delete, update, insert a record within Rails

How could Rails trigger the modification to elasticsearch? Thanks

model

require 'elasticsearch/model'
class Job < ActiveRecord::Base
  attr_accessor :deadline_asap
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks  

end

Rake task

For initial ES indexing

  task :import_all => :environment do
    Job.__elasticsearch__.create_index!
  end
1

There are 1 best solutions below

0
On

It should already be synchronized: adding

include Elasticsearch::Model::Callbacks

to your model should ensure that any modification will call the ElasticSearch API

To check this out, just modify a model and use your ES search, it should give you results including the frechly updated model.

Update: Here is the Automatic Callbacks documentation in ElasticSearch-Model gem