4

I'm running Rails with Elasticsearch using the elasticsearch-rails and will_paginate gems and things are working great.

The only problem I'm having is that my records count has grown over 10.000 which gives the error "Result window is too large, from + size must be less than or equal to: [10000] but was [10200]" when someone clicks on the last page of the pagination links.

Now I don't want to mess with index.max_result_window because my dataset is going be much much larger and I really don't need visitors to be able to view every page and record anyway.

So basically I just want to set a limit of 10.000 on my results but I'm having no luck getting that working.

This is the query I have in my controller action:

@response = Price.search(params)
@response = @response.paginate(page: params[:page], per_page: 24)
@prices = @response.records.includes(shop: :pictures)
@prices_count = @response.total_entries
@prices = @prices.decorate
@results = @response.results

And I feed the @response to will_paginate using

will_paginate(@response)

I've tried using .limit(10000) in various places and giving a total_entries value to will_paginate but nothing seems to work.

Do you guys have any ideas?

Thanks!

Reinier
  • 152
  • 1
  • 10

2 Answers2

1

I had the same Issue, in my case I'm using kaminari but should work the same with will_paginate:

= paginate @keyword_search_results

With 25 results per page after 400 page it throws the index.max_result_window error, so I just add the :total_pages option to paginate

= paginate @keyword_search_results, {:total_pages => 400}

Would be a good idea to calculate that value dynamically based on your needs.

Carlos Castillo
  • 3,218
  • 2
  • 14
  • 10
0

use per_page option
@response = Price.search(params, per_page: 24)

Shani
  • 2,433
  • 2
  • 19
  • 23