④. 数据迁移
- ①. 先创建new_twitter的正确映射,然后使用如下方式进行数据迁移。
6.0以后写法 POST reindex { "source":{ "index":"twitter" }, "dest":{ "index":"new_twitters" } } 老版本写法 POST reindex { "source":{ "index":"twitter", "twitter":"twitter" }, "dest":{ "index":"new_twitters" } }
②. 案例:原来类型为account,新版本没有类型了,所以我们把他去掉
GET /bank/_search { "took" : 0, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1000, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "bank", "_type" : "account",//原来类型为account,新版本没有类型了,所以我们把他去掉 "_id" : "1", "_score" : 1.0, "_source" : { "account_number" : 1, "balance" : 39225, "firstname" : "Amber", "lastname" : "Duke", "age" : 32, "gender" : "M", "address" : "880 Holmes Lane", "employer" : "Pyrami", "email" : "amberduke@pyrami.com", "city" : "Brogan", "state" : "IL" } }, ... GET /bank/_search 查出 "age":{"type":"long"}
③. 想要将年龄修改为integer,先创建新的索引
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", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "state": { "type": "keyword" } } } } 查看“newbank”的映射: GET /newbank/_mapping 能够看到age的映射类型被修改为了integer. "age":{"type":"integer"}