美文网首页
【ES从入门到实战】二十、全文检索-ElasticSearch-

【ES从入门到实战】二十、全文检索-ElasticSearch-

作者: runewbie | 来源:发表于2020-05-28 22:12 被阅读0次

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

相关文章

网友评论

      本文标题:【ES从入门到实战】二十、全文检索-ElasticSearch-

      本文链接:https://www.haomeiwen.com/subject/usizahtx.html