【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 入门教程

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。