elasticsearch修改索引字段类型


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


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

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


#获取旧索引的字段映射

GET /users/_mapping


#创建临时索引带映射

PUT /users_temp
{
    "mappings": {
"user": {
"properties": {
"age": {
"type": "long"
                },
            }
        }
    }
}


#复制数据

POST /_reindex
{
  "source": {
    "index": "users"
  }, 
  "dest": {
    "index": "users_temp"
  }
}


#删除旧索引

DELETE /users


#创建新索引带映射

PUT /users
{
    "mappings": {
"user": {
"properties": {
"age": {
"type": "long"
                },
            }
        }
    }
}

#复制数据

POST /_reindex
{
  "source": {
    "index": "users_temp",
    "query": {
      "match_all": {}
    }
  }, 
  "dest": {
    "index": "users"
  }
}


#删除临时索引

DELETE /users_temp


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