应用场景
搜索过程中,我们需要添加新的属性,如对于一个Text
类型新增Keyword
的Fields.
准备操作
- 更新对应Index的Mappping
- 创建新的Index, 如
PUT reindex_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
- 创建对应的Mapping,保持和新的结构一致
Reindex 索引
该操作仅在ES6及以上版本有效
reindex 数据到新的index,该步骤会超时,等等成功执行即可
POST _reindex
{
"source": {
"index": "index",
"type": "test_type"
},
"dest": {
"index": "reindex_index",
"type": "test_type"
}
}
{
"source": {
"index": "index",
"type": "test_type"
},
"dest": {
"index": "reindex_index",
"type": "test_type"
}
}
检查状态,状态一致后进行index重建步骤
GET index/test_type/_count
GET reindex_index/test_type/_count
GET reindex_index/test_type/_count
revert reindex,将reindex库的内容更新到原有库,完成更新操作
POST _reindex
{
"source": {
"index": "reindex_index",
"type": "test_type"
},
"dest": {
"index": "index",
"type": "test_type"
}
}
{
"source": {
"index": "reindex_index",
"type": "test_type"
},
"dest": {
"index": "index",
"type": "test_type"
}
}
检查还原数据的完整性
POST index/test_type/_count
{
"query": {
"exists":{
"field":"testField.keyword"
}
}
}
{
"query": {
"exists":{
"field":"testField.keyword"
}
}
}
Delete reindex
DELETE reindex_index
当前还没有任何评论