I developed microservice for search using hibernate search and spring boot.this service is called from another web application for search and they are connected to shared database.
But I have problem when I add,delete or update from web app. There is no auto indexing.
I know well that Each insert going through an EntityManager/HibernateFactory, will hit hibernate search and if the Entity is Indexed, it will also update the index.
But the problem with me that I insert data from the another Web application which don’t use EntityManager/HibernateFactory.
@Hibernate_Search
Well, if Hibernate Search is not there, it cannot be aware of the changes. The obvious solution would be to use Hibernate ORM + Hibernate Search in that other application, but I guess you cannot.
The only remaining solution would be to reindex periodically (e.g. every night), but that would mean giving up on almost-instantaneous index updates. Depending on your use case that might or might not be okay.
To reindex periodically, you will have to setup a scheduled task in your application (Spring offers ways of doing that), and in this task launch reindexing using one of these methods:
- “traditional” reindexing using the MassIndexer
- newer JSR352 integration (did not work with Spring Batch due to poor support of the standard, last time I checked)
Hi yoann,
I migrated hibernate search from 4.3 to 5.5.8 and found an issue like when I perform any CRUD operation reindexing started on that indexed entity and takes very long time, in my case 7 minutes but it was not the case in 4.3 version. The indexing strategy is configured as event based. Could you please advise on this issue?
Please start a separate topic and provide more information, in particular the mapping you are using. If you mapping is complex, it would help to provide a reproducer based on our test case templates.
Note however that you are using an old version of Hibernate Search: both Search 4.3 and Search 5.5 are old, the newest version being Search 5.10, and the newest version supporting Hibernate ORM 5.0/5.1 being Search 5.6. Any problem you encounter might have been fixed in more recent versions.
Thanks Yoann…much appreciated.
Hi @yrodiere
Thanks for your answer but i used different idea to do it.
I created web service in the microservice app to :
1-update index manually and after insert and update.
2-purge index manually after delete .
This web service is called by the another web application.
To Update index or Add
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
Object item = fullTextSession.load( Item.class,itemId);
fullTextSession.index(item);
tx.commit(); //index only updated at commit tim
To delete Item
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
fullTextSession.purge( Item.class, itemId);
tx.commit();
Glad you found a solution that is acceptable to you. Be warned, though: your web service is basically doing Hibernate Search’s work, and there are many performance and consistency pitfalls in that kind of work. It might be working now, but if the complexity (or scale) of your application increases, you might have to consider another strategy.