Reputation: 21884
I would like to have a clear understanding on how to deal with the following scenario:
I'm adding or removing an attribute from an activerecord model, so I want to update its mapping in ElasticSearch, in production.
From what I understood, I should...
Is this the right command? rake environment tire:import CLASS='Bow' INDEX='new-bows'
For this to create the right mapping, I should already have updated my mapping in the model, right?
bows
for new-bows
I would do it like that, is it correct?
old_index_name = Bow.tire.index.name
Bow.tire.index.delete
alias = Tire::Alias.new
alias.name(old_index_name)
alias.index('new-bows')
alias.save
Am I missing something, or is there a simpler way to achieve what I want using Tire?
At what point should I delete the old index? Before creating the alias with the same name, or can I do it after?
Upvotes: 2
Views: 2135
Reputation: 22515
To add a new column to an index:
index = Tire.index("articles")
index.mapping("article", :properties => { :pinterest_shares => {:type => 'integer', :index => 'not_analyzed', :include_in_all => false} })
Upvotes: 3
Reputation: 14419
You should keep the old index around until you're sure the new index is 100% what you want. You can flip the alias back if that would not be the case.
There's an integration test in Tire test suite for "flipping aliases".
Upvotes: 3