You should try to use Streams which have lazy loading and generally perform decently!
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.
Comments
This is the most common solution to this problem!