1

I am using ElasticsearchRepository and want to query on boolean property.

Sample snippet here:

class TempBean
{
       private boolean isActive;
}


interface MyEntityRepository implements CrudRepository<MyEntity, Long> 
{
   TempBean findByIsActiveTrue();
}

How to query on the active property without passing it as param to the abstract method? This is possible if I would have JpaRepository as per this answer how-to-query-for-boolean-property-with-spring-crudrepository

Community
  • 1
  • 1
Satish
  • 2,478
  • 2
  • 17
  • 22

1 Answers1

0

It is possible, as can be seen in the docs. Just remove "Is" from your function:

interface MyEntityRepository implements CrudRepository<MyEntity, Long> 
{
   TempBean findByActiveTrue();
}

As a side note, I don't know about your schema but I would suggest you use Page<TempBean> as your return type, which would require PageRequest as an argument. This is in case more than one TempBean docs have "active":"true" and your function is likely to return more than one records.

ystark
  • 565
  • 9
  • 18
  • sorry, I've updated the question. I got your answer. – Satish May 05 '16 at 06:55
  • My bad. I was probably hasty with my assessment of the question. But I'm still not sure what you want. You don't want to pass `isActive` as a parameter? – ystark May 05 '16 at 17:48