ES重建索引,数据迁移(_reindex)

当索引发生变化的时候,比如领导要求对字段a进行分词,我们可以使用该功能,新建一个索引将数据迁移过去,删掉原索引,再根据场景新建,将数据迁移回来就🆗了。

 

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/7.16/api-reference.html#_reindex

 

// 1. 将数据迁移到新的索引
POST _reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}

// 2. 删除老索引
DELETE /old_index

// 3. 新建索引并设置mapping
PUT /old_index
{
  "mappings": {
    "properties": {
      "a":{
        "type": "text",
        "analyzer": "ik_smart"
      },
      "b":{
        "type": "text",
        "analyzer": "ik_max_word"
      }
    }
  }
}
// 4. 将数据迁移回到原索引
POST _reindex
{
	"source":{
		"index":"new_index"
	},
	"dest":{
		"index":"old_index"
    }
}

  

posted @ 2022-07-21 10:14  小猪冒泡  阅读(811)  评论(0编辑  收藏  举报