The solution lies in changing your approach. For example, I populated a list of documents to be indexed, and then sent the whole list to the index.
A more appropriate solution would be to send each document one by one to the indexer and build the index gradually instead of handling really large object lists.