suresh t suresh t - 4 months ago 34
Java Question

To set a size in ElasticSearch using @Query

I'm using @query to retrieve the elasticsearch data through JPQL. the default size is 10, i mentioned the size as 5 in @Query but am getting 10 records but i need 5 to solve this problem


List findByBrand(String brand);

Val Val

You simply need to add a Pageable argument to your findByBrand method:

List findByBrand(String brand, Pageable pageable);

Then you can call that method like this:

List brands = findByBrand("mybrand", new PageRequest(0, 5));

Alternatively, you can also specify how many results you want in the method name itself:

List brands = findTop5ByBrand(String brand);