转载请标明出处:
http://blog.csdn.net/qq_27818541/article/details/109391849
本文出自:【BigManing的博客】
一、mapping中添加字段
kibana / es head 中操作
PUT book/_doc/_mapping
{
"properties": {
"bookNum": {
"type":"long"
}
}
}
响应
{
"acknowledged": true
}
核验
可以查询验证下mapping,字段是否添加上去了。
GET book/_doc/_mapping
二、给字段赋值默认值
_update_by_query
可以修改原字段或者新增字段,上面我们新增了bookNum
字段,接下来我们可以给其赋值默认值:
POST book/_doc/_update_by_query
{
"script":{
"lang":"painless",
"source":"if (ctx._source.bookNum == null) {ctx._source.bookNum = 0}"
}
}
响应成功:
{
"took": 31694,
"timed_out": false,
"total": 100313,
"updated": 100313,
"deleted": 0,
"batches": 101,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": []
}