Selecting custom fields of matching names


I am using HibernateSearch 6.0 Beta8 for querying data from ElasticSearch. I have to choose custom fields like empName and department alone from an index for all those employees whose names are “Kevin”, “Calvin” and “Ronnie”.

In Hibernate ORM

  1. we populate criteria
    criteria = criteria.add(“empName”, filterData.getEmployeeName()));
    criteria = criteria.add(“dept”, filterData.getDepartment()));
    List empList = criteria.list();

  2. select col1, col2,col5 from ;
    Need to select subset of columns

How do we acheive the above in Hibernate Search 6.0

Thanks In Advance.

Best Regards,
Srikanth C


Please have a look at the getting started guide. This will introduce you to the basics of search. Then you can have a look at the bool predicate to combine multiple predicates.

As to selecting specific columns from the database, there is no such feature (yet). You can only retrieve the whole entity from the database.

However, you can store data in the index, then retrieve it using projections.

Or, alternatively, you can retrieve just the entity IDs from Hibernate Search using an entityReference projection, then you’ll be able to run you own query on the database to retrieve the columns you want.