赞
踩
响应结果
{
"_index": "customer", // 在哪个索引
"_type": "external", // 在哪个类型
"_id": "1", // 记录id
"_version": 2, // 版本号
"_seq_no": 1, //并发控制字段,每次更新就会+1,用来做乐观锁
"_primary_term": 1, // 同上,主分片重新分配,如重启,就会变化
"found": true,
"_source": { //真正的内容
"name": "test"
}
}
postman中测试:
PUT http://localhost:9200/customer/external/1?if_seq_no=7&if_primary_term=1
只有_seq_no和_primary_term是最新值时,才能更新成功,如果不是,则返回409错误:
{ "error": { "root_cause": [ { "type": "version_conflict_engine_exception", "reason": "[1]: version conflict, required seqNo [7], primary term [1]. current document has seqNo [8] and primary term [1]", "index_uuid": "BVsVjaw_Rzaxkhu6LGd4-A", "shard": "0", "index": "customer" } ], "type": "version_conflict_engine_exception", "reason": "[1]: version conflict, required seqNo [7], primary term [1]. current document has seqNo [8] and primary term [1]", "index_uuid": "BVsVjaw_Rzaxkhu6LGd4-A", "shard": "0", "index": "customer" }, "status": 409 }
{
"doc": {
"name": "test111"
}
}
这种方式会将传入数据和原来的存储数据做比较,如果一样,则不执行更新,_version、_seq_no、_primary_term字段也不会发生变化
{
"name":"123"
}
这种方式不会将传入数据和原来的存储数据做比较,每次都会更新
{
"name": "qus",
"age": "男"
}
这种方式不会将传入数据和原来的存储数据做比较,每次都会更新
POST /index/type/_bulk
{action:{metadata}}
{requestBody}
{action:{metadata}}
{requestBody}
...
(1). action(行为):
create:文档不存在时创建
update:更新文档
index:创建新文档或替换已有文档
delete:删除一个文档
(create和index的区别:如果文档存在,使用create会失败,会提示文档已经存在;但使用index则可以成功执行,将替换已有文档)
(2). metadata:_index,_type,_id
示例:
POST /customer/external/_bulk
{"index":{"_id":"1"}}
{"name":"qus2"}
{"index":{"_id":"2"}}
{"name":"qus3"}
POST /_bulk
{"delete":{"_index":"website","_type":"blog","_id":"123"}}
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"123"}}
{"doc":{"title":"My update blog post"}}
POST /bank/account/_bulk
【此处贴入上述地址中的所有数据】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。