因为es索引结构特性 当我们对现有索引新增字段时并不会影响历史数据,并且如果没有写入这个字段值时,也不会有默认值
所以有时我们需要对历史数据设置默认值
1.使用put方法加字段
my_index/_mapping/my_type
{
"properties": {
"字段":{
"type": "类型"
}
}
}
2.设置默认值 使用post
my_index/_update_by_query
{
"script": {
"lang": "painless",
"inline": "if (ctx._source.字段== null) {ctx._source.字段= '0'}"
}
}