Update ElasticSearch mapping in production (Tire)

雨燕双飞 提交于 2019-12-07 19:23:08

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/15374330/update-elasticsearch-mapping-in-production-tire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!