# Elasticsearch Rails Extra

In 

Paginate ElasticsearchRails response objects.

# Setup

pagy.rb (initializer)
require 'pagy/extras/elasticsearch_rails'

# Modes

This extra offers two ways to paginate ElasticsearchRails response objects.

# Usage

Model
extend Pagy::ElasticsearchRails
Controller (pagy_search)
# get the collection in one of the following ways
collection = Article.pagy_search(params[:q])
collection = Article.pagy_search(params[:q]).records
collection = Article.pagy_search(params[:q]).results
# paginate it
@pagy, @response = pagy_elasticsearch_rails(collection, limit: 10)

# Usage

Controller (search)
# standard response (already paginated)
@response = Article.search('*', from: 0, size: 10, ...)
# get the pagy object out of it
@pagy = Pagy.new_from_elasticsearch_rails(@response, ...)

# Variables

Variable Description Default
:elasticsearch_rails_pagy_search customizable name of the pagy search method :pagy_search
:elasticsearch_rails_search customizable name of the original search method :search

# Methods

This method accepts the same arguments of the search method and you must use it in its place in active mode.

This constructor accepts an Elasticsearch::Model::Response::Response, plus the optional pagy variables. It automatically sets the :limit, :page and :count pagy variables extracted/calculated out of it.

This method is similar to the generic pagy method, but specialized for Elasticsearch Rails (see the pagy doc).

It expects to receive YourModel.pagy_search(...) result and returns the paginated response.