简体   繁体   中英

How i can do Elastic search by all fields (Spring)?

I have application with Spring Boot and elastic serch. For searching i use ElasticsearchRepository from org.springframework.data.elasticsearch.repository.ElasticsearchRepository

How i can do search by all fields with pagination?

Now my code look like that:

public interface ElasticRepo extends ElasticsearchRepository<ModelDao, Long> {
  @Query("{\"query\": {\"match\": {\"_all\": \"?\"}}}")
    Page<ModelDao> findByAllUsingCustomQuery(String name, Pageable pageable);
}

I use this interface as:

@Autowired
private ElasticRepo elasticRepo;

 public Page<TransportationRequestDao> getOrdersPageable(Pageable pageable, String q) {
     return elasticRepo.findByAllUsingCustomQuery(q, pageable);
 }

And i call this method( getOrdersPageable ) from HTTP query

But i get answer without result.

Can you help me?

I think solve your problem by using bellow code

@Service
class ElasticService{
    
@Autowired
private ElasticRepo elasticRepo;
    
public List<> customQuery() {
String name = "every thing";
return elasticRepo.findByAllUsingCustomQuery(name,Pageable.of(1,20));
}
}

you should using Pageable.of(1,20) method. that first parameter is index of page and second parameter is length of items in per page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM