![](/img/trans.png)
[英]Can I search by multiple fields using the Elastic Search Java API?
[英]How i can do Elastic search by all fields (Spring)?
我有 Spring Boot 和弹性搜索的应用程序。 对于搜索,我使用org.springframework.data.elasticsearch.repository.ElasticsearchRepository
ElasticsearchRepository
如何使用分页按所有字段进行搜索?
现在我的代码看起来像这样:
public interface ElasticRepo extends ElasticsearchRepository<ModelDao, Long> {
@Query("{\"query\": {\"match\": {\"_all\": \"?\"}}}")
Page<ModelDao> findByAllUsingCustomQuery(String name, Pageable pageable);
}
我使用这个接口作为:
@Autowired
private ElasticRepo elasticRepo;
public Page<TransportationRequestDao> getOrdersPageable(Pageable pageable, String q) {
return elasticRepo.findByAllUsingCustomQuery(q, pageable);
}
我从 HTTP 查询中调用这个方法( getOrdersPageable
)
但我得到了没有结果的答案。
你能帮助我吗?
我认为通过使用波纹管代码解决您的问题
@Service
class ElasticService{
@Autowired
private ElasticRepo elasticRepo;
public List<> customQuery() {
String name = "every thing";
return elasticRepo.findByAllUsingCustomQuery(name,Pageable.of(1,20));
}
}
你应该使用Pageable.of(1,20)
方法。 第一个参数是页面索引,第二个参数是每页项目的长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.