Old version of the entity retrieved although index was updated

This whole behavior is caused by a wrong use of EntityManager in BookSearch:

    public BookSearch(final EntityManagerFactory entityManagerFactory) {
        this.entityManager = entityManagerFactory.createEntityManager();

    }

You’re creating a single entity manager, and reusing it forever.
The first time you search, a book will be retrieved from the database, and put into the session.
The next time you search, the book will still be in the session, and will get reused. Without being updated, since it’s the same session.

So you will always get the same content in your entities.

Try this instead:

@PersistenceContext
EntityManager entityManager;

    public BookSearch() {
    }

And encapsulate the various phases of your tests in transactions. This will save you a lot of headaches…

@SpringBootTest
class HibernateSearchApplicationTests {

    @Autowired
    BookRepository bookRepository;

    @Autowired
    BookSearch bookSearch;

    @Autowired
    TransactionTemplate transactionTemplate;

    @Test
    void crudTest() {
        UUID bookId = UUID.randomUUID();

        transactionTemplate.execute(ignored -> {
            Book book = new Book();
            book.setId(bookId);
            book.setTitle("space");
            book.setGenre("Sci-Fi");
            bookRepository.save(book);
            return null;
        });
        transactionTemplate.execute(ignored -> {
            List<Book> books = bookSearch.getByTitle("space");
            print(books);
            // actual: result books size = 0
            // should have been size = 1
            return null;
        });

        transactionTemplate.execute(ignored -> {
            Book book = bookRepository.findById(bookId).get();
            book.setTitle("2001: Space Odyssey");
            book.setGenre("Sci-Fi");
            bookRepository.save(book);
            return null;
        });
        transactionTemplate.execute(ignored -> {
            List<Book> books = bookSearch.getByTitle("space");
            print(books);
            // actual: result books size = 1 with title = "space"
            // KO: should have been size size = 1 with title = "2001: Space Odyssey"
            return null;
        });

        transactionTemplate.execute(ignored -> {
            Book book = bookRepository.findById(bookId).get();
            book.setTitle("2010: Odyssey Two");
            book.setGenre("Sci-Fi");
            bookRepository.save(book);
            return null;
        });

        transactionTemplate.execute(ignored -> {
            List<Book> books = bookSearch.getByTitle("space");
            print(books);
            // actual: size = 0
            // OK: size = 0
            return null;
        });
        transactionTemplate.execute(ignored -> {
            List<Book> books = bookSearch.getByTitle("2001: Space Odyssey");
            print(books);
            // actual: books size = 1 with title = "2001: Space Odyssey"
            // KO: should have been "2010: Odyssey Two"
            assertEquals(books.get(0).getTitle(), "2010: Odyssey Two");
            return null;
        });

        transactionTemplate.execute(ignored -> {
            Book book = bookRepository.findById(bookId).get();
            bookRepository.delete(book);
            return null;
        });
    }

    private void print(List<Book> books) {
        System.out.println("----- Size: " + books.size());
        if (books.size() > 0) {
            System.out.println("------- Title: " + books.get(0).toString());
        }
    }
}