Speeding up atomic operations (bulk operations)
When we are inserting, deleting, or updating a large number of documents, the HTTP overhead is significant. To speed up the process, ElasticSearch allow to execute bulk CRUD (Create, Read, Update, Delete) calls.
Getting ready
You will need a working ElastiSearch cluster.
How to do it...
As we are changing the state of the data, the HTTP method is POST and the REST URL is:
http://<server>/<index_name/_bulk
To execute a bulk action, we will perform the steps given as follows:
We need to collect the Create, Index, Delete, Update commands in a structure made of bulk JSON lines, composed by a line of action with metadata and another line with optional data related to the action. Every line must end with a newline,
\n
. The bulk data file should be, for example:{ "index":{ "_index":"myindex", "_type":"order", "_id":"1" } } { "field1" : "value1", "field2" : "value2" } { "delete":{ "_index":"myindex", "_type":"order", "_id":"2" } } { "create":{...