Hibernate Search - Indexing not working on insertion

I’m using Hibernate Search(v7.1.0) along with Hibernate ORM(6.4.0) in my SpringBoot application and I have a method which is @Transactional and it persist list of objects into the database using JPA repository but it doesn’t index the data automatically while data is persisted in database correctly. It only get indexed if I fetch those records by ids and update all those records with anything or relaunch the whole application and get it indexed by onLaunch MassIndexer.

Hey,

Thanks for reaching out. Based on the info you’ve provided, it is not entirely clear what your configuration is. Maybe your index is not yet refreshed, or maybe you’ve disabled the refresh entirely?

persist list of objects into the database using JPA repository

Does using an EntityManager directly instead of the repository to persist the entities work?

If not, can you create a simple reproducer using the template hibernate-test-case-templates/search/hibernate-search-7 at main · hibernate/hibernate-test-case-templates · GitHub ?

Thanks!

Thanks for your response.

I don’t know if it is disabled, I’m using default configurations. If it is disabled, then why indexes get updated on updating the records after getting it using findByIDs.

I’ve used EntityManager directly and data gets persisted successfully but it doesn’t index it or maybe not refreshed. I’ve waited for minutes but it didn’t work.

Regarding configurations, I’m using NoCoordination which is default and synchronization strategy is write-sync which is also default

How can I check if my persisted records are part of SearchIndexingPlan or indexed and not yet refreshed?

Can you try a read-sync or sync strategy (Hibernate Search 7.2.0.Final: Reference Documentation), to see if that helps (if you need to perform search right after the persist). You’d need to set a hibernate.search.indexing.plan.synchronization.strategy but if it’s a Spring Boot app you’ll probably need to add it with the spring.jpa.properties. prefix: spring.jpa.properties.hibernate.search.indexing.plan.synchronization.strategy=read-sync

Regarding this, it is not visible in search even after minutes. It should be visible right?

I’ve tried with both (read-sync & sync) either of them aren’t working. How can I check if my persisted records are part of SearchIndexingPlan or even indexed? Maybe persistence event is not getting recorded by Hibernate Search.

Yes, that’s the expectation: the index will eventually be refreshed, and the documents will become searchable.

If you can debug your application, then the easiest way would be to put a breakpoint in the listener (HibernateSearchEventListener) somewhere here: hibernate-search/mapper/orm/src/main/java/org/hibernate/search/mapper/orm/event/impl/HibernateSearchEventListener.java at 561f3c48f613c8b83d6a57292824ffacdee4edc7 · hibernate/hibernate-search · GitHub