elasticsearch修改索引字段类型


elasticsearch不支持直接修改字段类型,解决思路:


新建临时索引,执行字段类型,复制数据

删除旧索引,重建同名索引,从临时索引复制数据


#获取旧索引的字段映射

1
GET /users/_mapping


#创建临时索引带映射

1
2
3
4
5
6
7
8
9
10
11
12
PUT /users_temp
{
    "mappings": {
"user": {
"properties": {
"age": {
"type""long"
                },
            }
        }
    }
}


#复制数据

1
2
3
4
5
6
7
8
9
POST /_reindex
{
  "source": {
    "index""users"
  }, 
  "dest": {
    "index""users_temp"
  }
}


#删除旧索引

1
DELETE /users


#创建新索引带映射

1
2
3
4
5
6
7
8
9
10
11
12
PUT /users
{
    "mappings": {
"user": {
"properties": {
"age": {
"type""long"
                },
            }
        }
    }
}

#复制数据

1
2
3
4
5
6
7
8
9
10
11
12
POST /_reindex
{
  "source": {
    "index""users_temp",
    "query": {
      "match_all": {}
    }
  }, 
  "dest": {
    "index""users"
  }
}


#删除临时索引

1
DELETE /users_temp


鼎云博客
  • 最新评论
  • 总共0条评论