接上一篇:
11、更新文档
curl -XPOST http://localhost:9200/_bulk -d'
{ action: { metadata }}\n
{ request body }\n
{ action: { metadata }}\n
{ request body }\n
'
| 操作类型 | 说明 |
| create | 当文档不存在时创建之。 |
| index | 创建新文档或替换已有文档。 |
| update | 局部更新文档。 |
| delete | 删除一个文档。 |
比如下面的操作:
首先删除一个文件
再新建一个文件
然后全局更加一个文件
最后局部更新一个文件
curl -XPOST http://localhost:9200/_bulk -d'
{ "delete": { "_index": "myindex", "_type": "user", "_id": "u004" }}
{ "create": { "_index": "myindex", "_type": "user", "_id": "u004" }}
{"用户ID": "u004","姓名":"赵六","性别":"男","年龄":"27","家庭住址":"深圳市龙岗区特区大街011号","注册时间":"2015-04-01 08:30:00"}
{ "index": { "_index": "myindex", "_type": "user", "_id": "u004" }}
{"用户ID": "u004","姓名":"赵六","性别":"男","年龄":"28","家庭住址":"深圳市龙岗区特区大街012号","注册时间":"2015-04-01 08:30:00"}
{ "update": { "_index": "myindex", "_type": "user", "_id": "u004"} }
{ "doc" : {"年龄" : "28"}}
结果如下:(局部更新没有执行,没查到原因)
{
"took": 406,
"errors": false,
"items": [
{
"delete": {
"_index": "myindex",
"_type": "user",
"_id": "u004",
"_version": 10,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 200,
"found": true
}
},
{
"create": {
"_index": "myindex",
"_type": "user",
"_id": "u004",
"_version": 11,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 201
}
},
{
"index": {
"_index": "myindex",
"_type": "user",
"_id": "u004",
"_version": 12,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 200
}
}
]
}