【问题标题】:How i can do Elastic search by all fields (Spring)?我如何按所有字段进行弹性搜索(Spring)?
【发布时间】:2021-02-04 17:03:30
【问题描述】:

我有带有 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

但我得到了没有结果的答案。

你能帮帮我吗?

【问题讨论】:

    标签: java spring spring-boot elasticsearch spring-data


    【解决方案1】:

    我认为使用下面的代码可以解决您的问题

    @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) 方法。第一个参数是页面索引,第二个参数是每页项目的长度。

    【讨论】:

    • 但这很明显!我正在使用类似的代码来使用接口ElasticRepo
    • 我将此添加到我的答案中
    猜你喜欢
    • 2021-01-24
    • 2020-02-04
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多