索引为 test , 添加一个 code 字段

PUT test/_mapping
{
    "properties": {
      "code": {
        "type": "keyword"
      }
    }
}

如果给 code 字段添加默认值

POST test/_update_by_query
{
  "script": {
    "lang": "painless",
    "inline": "if (ctx._source.code == null) {ctx._source.code= 'test'}"
  }
}