Batch indexing to speed up your indexing process
In the first chapter, we've seen how to index a particular document into Elasticsearch. Now, it's time to find out how to index many documents in a more convenient and efficient way than doing it one by one.
Preparing data for bulk indexing
Elasticsearch allows us to merge many requests into one packet. These packets can be sent as a single request. In this way, we can mix the following operations:
Adding or replacing the existing documents in the index (
index
)Removing documents from the index (
delete
)Adding new documents to the index when there is no other definition of the document in the index (
create
)
The format of the request was chosen for processing efficiency. It assumes that every line of the request contains a JSON object with the description of the operation followed by the second line with a JSON object itself. We can treat the first line as a kind of information line and the second as the data line. The exception to this rule is the...