elasticsearch 添加字段设置默认值。

开启动态脚本功能,在config/elasticsearch.yml文件,在最后添加以下代码:

script.inline: on
script.indexed: on
script.file: on

配置后,重启Elasticsearch。

POST

http://127.0.0.1:9200/my_index/my_type/_update_by_query

{
  "script": {
	"inline": "if (ctx._source.status_code == null) {ctx._source.status_code= '02'}"
  }
}

使用string 类型的字段设置默认值

http://127.0.0.1:9200/my_index/mapp/my_type   put

{
  "properties": {
	"status_code": {
	  "type": "string",
	  "index": "not_analyzed",
	  "null_value": "NULL"
	}
  }
}