[ES from entry to actual combat] 20, full-text search-ElasticSearch-mapping-modify mapping & data migration

Continue to section 19

4. Data migration

First create the correct mapping for twitter. Then use the following method for data migration

# 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"
  }
}

For example
创建一个新的索引:

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"
      }
    }
  }
}

Insert picture description here

数据迁移

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

Insert picture description here
查看迁移后的数据:
You can see that old data can be migrated without type

GET newbank/_search

Insert picture description here

Reference document-mapping


reference:

Elasticsearch Reference

elastic

Getting started with the full-text search engine Elasticsearch

Guess you like

Origin blog.csdn.net/runewbie/article/details/106414621
Recommended