Joining Two Indexes


We are having two index corresponding to two entities:

@Table(name = “A”)
public class A{

@Table(name = “B”)
public class B{

Is it possible to create a join in the query to retrieve result from both index by joining on some common identifier?


You can target both indexes in a single query, so as to retrieve results of type A or B in the same result list:

FullTextQuery query = fullTextEntityManager.createQuery( luceneQuery, A.class, B.class );
List<Object> results = query.getResultList(); // Contains some objects of type A and some objects of type B

But if you really want a join, then no, Hibernate Search does not provide that feature. Multi-entity queries are generally achieved with @IndexedEmbedded, by embedding other entities in an entity’s index. See this section of the documentation.