Now the problem is when auto-wired searchSession will fetch result first time after storing data in db and indexing data is correct.
but suppose in a subsequent call to update the entity after indexing and then searching again in updated value will result empty result set.
if tried with another index there is inconsistency in data as data in database updated but in result ill get old data.
I found some solution for that however performance wise its not a correct approach.
here is what I did
in the beginning of search just clear the entity manager like this
please provide a proper solution to tackle this situation
The SearchSession must be obtained from the actual entity manager assigned to each request. Here you just create it once and reuse it everywhere; this will not work properly. There are probably ways to define a SearchSession bean in Spring that would be correctly scoped to the request, but this is not it. A simple alternative is to just inject the EntityManager everywhere you work with Hibernate Search, and extract a SearchSession using Search.session(entityManager).
Mass indexing must occur the first time you start your application, and each time you change your mapping. Nothing more: mass indexing is a heavy process and you can’t just do it on every request. Typically you would trigger mass indexing manually as part of the deployment process of your application (e.g. click on a button in the administration console of your application).
ok got your point about entity manager, however working with spring data jpa and in here we are not suggested to manually do anything in ‘EntityManager’ rather we are working with repositories always.
can u please suggest in this case how we will get the same ‘EntityManager’ which jpa is using to perform the action
here is mine configuration