In addition to being able to index, update, and delete individual documents, Elasticsearch also provides the ability to perform any of the above operations in batches using the _bulk
API. This functionality is important in that it provides a very efficient mechanism to do multiple operations as fast as possible with as few network roundtrips as possible.html
curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d' {"index":{"_id":"1"}} {"name": "John Doe" } {"index":{"_id":"2"}} {"name": "Jane Doe" } '
使用postMan調用時
{"index":{"_id":"1"}}
{"name": "John Doe" }
//此處必須換行 {"index":{"_id":"2"}} {"name": "Jane Doe" }
//此處必須換行
This example updates the first document (ID of 1) and then deletes the second document (ID of 2) in one bulk operation:json
curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d' {"update":{"_id":"1"}} {"doc": { "name": "John Doe becomes Jane Doe" } } {"delete":{"_id":"2"}} '
使用postMan調用時
與上面同樣,須要經過換行分隔
Note above that for the delete action, there is no corresponding source document after it since deletes only require the ID of the document to be deleted.網絡