Today, people need to use create an association to go from an embedded entity B to the containing entity A and annotate it with @ContainedIn. This is necessary for us to know which instance of A contains the instance of B.
This is sometimes undesirable as the association is not necessary for the application. This is particularly true of ToMany associations.
An alternative approach would be to let the user express a query instead of materializing an association.
I think that's a not too complicated feature that can be done by a community member.
Yoann: it is complicated, because the query approach makes little sense if we don't provide a way to "chunk" reindexing, i.e. a way to retrieve a batch of entities from the query, reindex them, flush and clear the session, continue to the next batch, etc. If we don't do that, this query mechanism will only make sense for associations with a small cardinality (an association with 8000 linked entities is a no-no). But such a chunked reindexing is hard (impossible?) to implement properly:
we would ideally want it to read from the user session's cache, but never, ever write to the user sessions's cache (in particular the clear() calls should not remove entities that the user expects to be in the session).
depending on the number of entities to reindex, the reindexing process could take a lot of time. We may want to make reindexing
In conclusion, it's likely that such a feature only makes sense if we implement asynchronous processing of entity change events (HSEARCH-2364). Since integrating the two features would likely require API changes, I'd rather work on this ticket after is solved.
We might want to abstract away from a query string and use an interface / implementation so that Hibernate Search working in non ORM environment can still benefit from this approach. I haven't thought much about this abstraction.