Can siblings of field _source (e.g. _type) found in Elasticsearch indexed documents be projected in (Hibernate Search) query results?
Not currently. However, we expose a few projections that should address most use cases. In particular, to fetch the type, you can use the Hibernate Search specific projection org.hibernate.search.elasticsearch.ElasticsearchProjectionConstants#OBJECT_CLASS
, which will give your the class of the indexed entity.
For example:
import static org.hibernate.search.elasticsearch.ElasticsearchProjectionConstants;
...
FullTextQuery<?> query = ...;
query.setProjection( ElasticsearchProjectionConstants.OBJECT_CLASS, ElasticsearchProjectionConstants.ID );
List<List<?>> results = (List<List<?>>) query.getResultList();
for ( List<?> projection : results ) {
Class<?> objectClass = (Class<?>) projection.get( 0 );
Object objectId = projection.get( 1 );
// ... do something with the data ...
}