ES已有mapping下,新增字段且设置初始值

发布时间:2024年01月19日

开发过程中随着业务的发展,内容累计,中途需要添加新的字段,并且设置初始值。

# 先查询原来的mapping
GET test_index/_mapping 

# 新增字段
PUT test_index/_mapping
{
  "properties": {
    "name": {
      "type": "text"
    }
  }
}


# 历史数据设置初始值
POST test_index/_update_by_query
{
  "script": {
    "lang": "painless",
    "source": "if (ctx._source.name== null) {ctx._source.name=  ''}"
  }
}

参考文档:
ES 7.17x官方文档

文章来源:https://blog.csdn.net/smile_68/article/details/135703115
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。