查询ElasticSearch存储库中的布尔字段

时间:2016-05-02 07:48:31

标签: elasticsearch spring-data-elasticsearch

我正在使用ElasticsearchRepository并想查询布尔属性。

此处的示例代码段:

class TempBean
{
       private boolean isActive;
}


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

如何查询活动属性而不将其作为抽象方法的参数传递? 如果我按照这个答案how-to-query-for-boolean-property-with-spring-crudrepository

获得JpaRepository,这是可能的

1 个答案:

答案 0 :(得分:0)

可以在docs中看到。只需从您的函数中删除“Is”:

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

作为旁注,我不了解您的架构,但我建议您使用Page<TempBean>作为返回类型,这需要PageRequest作为参数。如果多个TempBean文档有"active":"true",您的函数可能会返回多个记录。

相关问题