suresh t suresh t - 1 year ago 104
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
Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download