本文共 710 字,大约阅读时间需要 2 分钟。
主要介绍当在ES中添加了document后,如何更新、删除、批量操作数据。
1、更新文档
PUT /customer/_doc/1?pretty{ "name": "John Doe"}
说明:更新与保存都是使用put方法。
2、删除文档
DELETE /customer/_doc/2?pretty
说明:可以通过 删除匹配到指定内容的所有文档
3、批量操作文档
批量操作文档时,api接口为_bulk ,每一行数据必须以换行符\n结束。每个换行符前面可以有一个回车\r。向该端点发送请求时,应该将Content-Type头设置为application/x-ndjson。里面执行的动作可以是index,create,delete,update。其中index和create的下一行中,必须要含一个源文件。update希望在下一行指定部分doc、upsert和脚本及其选项,例如
POST /customer/_bulk?pretty{"index":{"_id":"1"}}{"name": "John Doe" }{"index":{"_id":"2"}}{"name": "Jane Doe" }
将保存两个document,在index的下一行紧跟着文档的内容
POST /customer/_bulk?pretty{"update":{"_id":"1"}}{"doc": { "name": "John Doe becomes Jane Doe" } }{"delete":{"_id":"2"}}
第一行为更新id为1的document,第三行为更新document。
转载地址:http://jdktn.baihongyu.com/