We solved that customizing TransactionalWorker, to make it flush and this way free the memory after given number of operations. That's what I would expect worker.batch_size to do, below the code:
public class TransactionalFlushingWorker extends TransactionalWorker {
private static final int INDEX_BATCH_SIZE = 2000;
private final AtomicInteger indexingWithoutFlushCounter = new AtomicInteger();
public void performWork(Work<?> work, TransactionContext transactionContext) {
super.performWork(work, transactionContext);
if (indexingWithoutFlushCounter.incrementAndGet() > INDEX_BATCH_SIZE) {
flushWorks(transactionContext);
}
}
public void flushWorks(TransactionContext transactionContext) {
indexingWithoutFlushCounter.set(0);
super.flushWorks(transactionContext);
}
}
registration:
hibernateProperties.put("hibernate.search.worker.scope", TransactionalFlushingWorker.class.getName());