# Selecting custom fields of matching names

**URL:** <https://discourse.hibernate.org/t/selecting-custom-fields-of-matching-names/4428>\
**Category:** Hibernate Search\
**Created:** [July 27, 2020, 8:34am UTC](https://discourse.hibernate.org/t/selecting-custom-fields-of-matching-names/4428 "2020-07-27T08:34:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![schoppara](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@schoppara](https://discourse.hibernate.org/u/schoppara)\
**Post date:** [July 27, 2020, 8:34am UTC](https://discourse.hibernate.org/t/selecting-custom-fields-of-matching-names/4428/1 "2020-07-27T08:34:46Z")

</div>

Hi,

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  
ex:-  
criteria = criteria.add(Restrictions.in(“empName”, filterData.getEmployeeName()));  
criteria = criteria.add(Restrictions.in(“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

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [July 27, 2020, 8:50am UTC](https://discourse.hibernate.org/t/selecting-custom-fields-of-matching-names/4428/2 "2020-07-27T08:50:49Z")

</div>

Hi,

Please have a look at the [getting started guide](https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#getting-started-searching). This will introduce you to the basics of search. Then you can have a look at the [`bool` predicate](https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#search-dsl-predicate-boolean) 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](https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#search-dsl-projection).

Or, alternatively, you can retrieve just the entity IDs from Hibernate Search using an [`entityReference` projection](https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#search-dsl-projection-reference), then you’ll be able to run you own query on the database to retrieve the columns you want.
