Ahoy fellow developers!
I have a problem with limiting the total number of search results in my web application.
The web app is written in Ruby, the search functionality is powered by ElasticSearch, and the pagination is handled by the Pagy ruby gem (documentation is available here).
In my ElasticSearch query, I use the size
parameter to limit the number of results. The limit works fine when I execute the query in Kibana. However, once I pass it to the Pagy gem method (pagy_elasticsearch_rails
, in particular), the size
value is overwritten by the items
one (which I pass to set the results per page limit). As a result, the total limit I set in the ElasticSearch (120 records) query is lost.
Here's how I pass the query to the pagy_elasticsearch_rails
method:
es_query = { min_score: 0.5, query: <the actual query body>, size: 120 }
collection = MyModel.pagy_search(es_query)
@pagy, @response = pagy_elasticsearch_rails(collection, items: 24)
Do you know how can I keep the total limit I set by the size
parameter, and make it work with the items
one?
Thank you!