es之零停机重新索引数据
某一个字段的类型不符合后期的业务了,但是当前的索引已经创建了,我们知道es在字段的mapping建立后就不可再次修改mapping的值
PUT articles1
{
"settings":{
"number_of_shards":3,
"number_of_replicas":1
},
"mappings":{
"article":{
"dynamic":"strict",
"properties":{
"id":{"type": "text", "store": true},
"title":{"type": "text","store": true},
"readCounts":{"type": "integer","store": true},
"times": {"type": "text", "index": "not_analyzed"}
}
}
}
}
PUT articles1/article/1
{
"id" : "1",
"title" : "世界1",
"readCounts" : 2 ,
"times" : "2018-05-01"
}
2):
当前的times是text类型,但是后期想使用时间去检索数据是不可能的了,那么在实际的生产中,我们是这样去解决的:
PUT articles2
{
"settings":{
"number_of_shards":3,
"number_of_replicas":1
},
"mappings":{
"article":{
"dynamic":"strict",
"properties":{
"id":{"type": "text", "store": true},
"title":{"type": "text","store": true},
"readCounts":{"type": "integer","store": true},
"times": {"type": "date", "index": "not_analyzed"}
}
}
}
}
}
但是此时仅仅是创建,另一个索引的数据并没有迁移过来:GET articles2/article/1
3):
创建别名
POST /_aliases
{
"actions": [
{ "add": { "index": "articles1", "alias": "my_index" }},
{ "add": { "index": "articles2", "alias": "my_index" }}
]
}
4):
查询当前别名下的所有索引:
GET /*/_alias/my_index
5):
数据重新索引
POST _reindex
{
"source": {
"index": "articles1"
},
"dest": {
"index": "articles2"
}
}
6):
查看数据是否进入新的索引
GET articles2/article/1