开发过程中随着业务的发展,内容累计,中途需要添加新的字段,并且设置初始值。
# 先查询原来的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官方文档