首页 > 其他 > 详细

Elasticsearch 批处理

时间:2019-09-10 09:45:56      阅读:72      评论:0      收藏:0      [点我收藏+]

章节


除了对单个文档执行创建、更新和删除之外,Elasticsearch还提供了使用_bulk API批量执行上述操作的能力。

下面的调用,在一个批量操作中,创建两个文档(ID 1 - John Doe和ID 2 - Jane Doe):

API

POST /customer/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }

CURL

curl -X POST "localhost:9200/customer/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'

下面的例子,在一个批量操作中,先更新第一个文档(ID为1),再删除第二个文档(ID为2):

API

POST /customer/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}

CURL

curl -X POST "localhost:9200/customer/_bulk?pretty" -H 'Content-Type: application/json' -d'
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'

注意,对于delete操作,只需提供被删除文档的ID即可。

某个操作失败不会导致批量API执行中断,剩下的操作将继续执行。当_bulk API返回时,它将为每个操作提供一个状态(与发送操作的顺序相同),以便检查某个特定操作是否失败。

Elasticsearch 批处理

原文:https://www.cnblogs.com/jinbuqi/p/11495476.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!