Thanks for all the help, I really apricate it and I have learnt a lot about how Lucene works. I tried the Transaction as described in the linked question but it did not work, but some more messing on my branch for Hibernate 6 search and when I annotated my search method in the Search service with: @Transactional(readOnly = true), using org.springframework.transaction.annotation.Transactional it works, I tried it previously but I seemingly did something else wrong back then. But when I configure my test to run in one transaction with rollback after test it fails (i.e annotate the test class with @Transactional.). But maybe that is not possible now? I found a workaround which is to annotate my test classes with this:
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY)
Which gives each test an clean database
Most likely my original problem was that I had my test wrapped in a transaction with rollback after test so that I could have independent dataset for each test. And if you annotate the test class with Transactional then the Transactional annotation on the search method has no effect.