简体   繁体   中英

Update ElasticSearch mapping in production (Tire)

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...

1- create a new index and import everything from mysql

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?

2- delete the old mapping and create an alias named 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

3- restart app


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?

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".

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} })

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