docs/toolbox/paginators/elasticsearch_rails.md
:elasticsearch_rails is a SEARCH paginator for ElasticsearchRails response objects.
=== :icon-tools: Usage
+++ Active mode
!!!success Pagy searches and paginate
You use the pagy_search method in place of the search method.
!!!
extend Pagy::Search
# Get the search in one of the following ways
search = Article.pagy_search(params[:q])
search = Article.pagy_search(params[:q]).records
search = Article.pagy_search(params[:q]).results
# Paginate it
@pagy, @response = pagy(:elasticsearch_rails, search, **options)
+++ Passive mode
!!!success You search and paginate Pagy creates its object out of your result. !!!
# Standard response (already paginated)
@response = Article.search('*', from: 0, size: 10, ...)
# Get the pagy object out of it
@pagy = pagy(:elasticsearch_rails, @response, **options)
+++
!!! Search paginators don't query a DB, but use the same positional technique as :offset paginators, with shared options and readers. !!!
==- :icon-sliders: Options
search_method: :my_search
: Customize the name of the elasticsearch_rails method to use (default :search).
{{ include "options/paginator" }}
==- :icon-mention: Readers
{{ include "snippets/offset-readers" }}
===