Skip to content

3.1 Bulk APIs

Madhusudhan Konda edited this page Oct 13, 2020 · 2 revisions

Bulk APIs

Indexing one a document is fun but it is surely a pain when you are supposed to onboard hundreds or even thousands of them. Here's where Elasticsearch provides us with a convenient API for batch/bulk indexing.

The _bulk API accepts a POST request which can perform index, create, delete, and update actions all in one go.

Let's see an example of indexing some data:

POST covid/_bulk
{"index":{"_index":"covid","_id":1}}
{"country":"United States of America","date":"2020-05-07","cases":1349599,"deaths":80101,"recovered":238081,"critical":16816}

The first line is the operation that we are expecting the API to perform - indexing the document in this case. The operation is then followed by an object of the metadata information which is the index name and the id of the document.

The second line is the actual data of your document in JSON format.

Clone this wiki locally