#创建索引m1
PUT m1
{
"mappings": {
"dynamic": "runtime",
"properties": {
"name": {
"type": "text"
},
"age": {
"type": "long"
}
}
}
}
#创建索引m2
PUT m2
{
"mappings": {
"dynamic": "runtime",
"properties": {
"name": {
"type": "text"
},
"age": {
"type": "long"
}
}
}
}
DELETE m1
DELETE m2
GET m1/_mapping
#查看所有别名
GET /_cat/aliases
#添加別名
POST _aliases
{
"actions": [
{
"add": {
"index": "m1",
"alias": "m1_v2"
}
}
]
}
#刪除別名
POST _aliases
{
"actions": [
{
"remove": {
"index": "m1",
"alias": "m1_v1"
}
}
]
}
#迁移数据
POST _reindex
{
"source": {
"index": "m1"
},
"dest": {
"index": "m2"
}
}
#一个别名也可以关联多个索引,这里是指定m2为写索引否则对别名进行写的时候报错,其他索引是读索引
POST _aliases
{
"actions":[
{"add":{"index":"m1","alias":"multi_v2"}},
{"add":{"index":"m2","alias":"multi_v2", "is_write_index" : true }}
]
}
##迁移数据从r2 迁移到 r3
#1.创建原来的索引
PUT /r2
{
"aliases" : {
"r" : { }
},
"settings": {
"number_of_shards": 6,
"number_of_replicas": 2
},
"mappings": {
"dynamic": "true",
"properties": {
"title": {
"type": "keyword"
}
}
}
}
#2创建新索引
PUT /r3
{
"settings": {
"number_of_shards": 12,
"number_of_replicas": 2
},
"mappings": {
"dynamic": "true",
"properties": {
"title": {
"type": "keyword"
}
}
}
}
#3一个别名也可以关联多个索引,这里是指定r3为写索引否则对别名进行写的时候报错,其他索引是读索引,同时删除旧索引的别名,看情况删,自己根据生产环境情况自己负责,如果不删除的话,搜索结果会多一倍出来
POST _aliases
{
"actions":[
{"add":{"index":"r3","alias":"r", "is_write_index" : true }}
{"remove":{"index":"r2","alias":"r"}},
]
}
ES 别名
于 2022-12-27 10:43:48 首次发布