I need to re-index all of my domain instances from a live legacy database on a regular basis using a custom ElasticSearch implementation.
All of the suggestions I have found so far have all been for optimizing batch write operations.
Many of the tables have hundreds of thousands if not millions of records and the simple solution of domain.list().each { ... } appears to load the entire dataset into memory at once.
Using Hibernate ScrollableResults seems like a good solution but it works at the RecordSet level and doesn't recreate the actual domain objects. I could use the id field to read() the instance but that seems inefficient.
The Searchable plugin seems to perform an efficient reindex operation.
What other options or optimizations are there for batch reading domain instances successfully?
UPDATE
I recently stumbled across a 4 year old thread on the Grails mailing list with an answer from @BurtBeckwith that suggests using a ScrollableResultSet would be inefficient. He recommends paging through the records using standard GORM methods and clearing the session in batches.