【ES从入门到实战】二十、全文检索-ElasticSearch-映射-修改映射&数据迁移

接第19节

4、数据迁移

先创建出 twitter 的正确映射。然后使用如下方式进行数据迁移

# 7.x 之后的写法
POST _reindex	//固定写法
{
    
    
  "source": {
    
    	//老索引
    "index": "twitter"
  },
  "dest": {
    
    		//目标索引
    "index": "new_twitter"
  }
}

# 7.x之前的带 type 的写法
将旧索引的 type 下的数据进行迁移
POST _reindex	//固定写法
{
    
    
  "source": {
    
    	
    "index": "twitter", //老索引
    "type": "twitter",  //老类型
  },
  "dest": {
    
    		//目标索引
    "index": "new_twitter"
  }
}

举例:
创建一个新的索引

PUT /newbank
{
    
    
  "mappings": {
    
    
    "properties": {
    
    
      "account_number": {
    
    
        "type": "long"
      },
      "address": {
    
    
        "type": "text"
      },
      "age": {
    
    
        "type": "integer"
      },
      "balance": {
    
    
        "type": "long"
      },
      "city": {
    
    
        "type": "keyword"
      },
      "email": {
    
    
        "type": "keyword"
      },
      "employer": {
    
    
        "type": "keyword"
      },
      "firstname": {
    
    
        "type": "text"
      },
      "gender": {
    
    
        "type": "keyword"
      },
      "lastname": {
    
    
        "type": "text"
      },
      "state": {
    
    
        "type": "keyword"
      }
    }
  }
}

在这里插入图片描述

数据迁移

POST _reindex
{
  "source": {
    "index": "bank",
    "type": "account"
  },
  "dest": {
    "index": "newbank"
  }
}

在这里插入图片描述
查看迁移后的数据
可以看到,不用 type,老的数据可以迁移过来

GET newbank/_search

在这里插入图片描述

参考文档-mapping


参考:

Elasticsearch Reference

elastic

全文搜索引擎 Elasticsearch 入门教程

猜你喜欢

转载自blog.csdn.net/runewbie/article/details/106414621
今日推荐