Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Kaminari with Elasticsearch::Persistence::Model #338

Closed
infiniteiteration opened this issue Mar 2, 2015 · 12 comments
Closed

Using Kaminari with Elasticsearch::Persistence::Model #338

infiniteiteration opened this issue Mar 2, 2015 · 12 comments
Labels

Comments

@infiniteiteration
Copy link

Hi, I tried to use Kaminari with Elasticsearch::Persistence::Model, but it does not work yet it seems. Is there a way to paginate a Elasticsearch::Persistence::Model? Or is it somewhere on the roadmap?

Thank you!

@twigbranch
Copy link

We have a similar issue with will_paginate...
undefined method `paginate' for #<Elasticsearch::Persistence::Repository::Response::Results:

@karmi
Copy link
Contributor

karmi commented Mar 3, 2015

There is no automatic support for Kaminari/WillPaginate yet, but it's of course planned.

@karmi karmi added the feature label Mar 3, 2015
@andreacfm
Copy link

+1

2 similar comments
@amal007
Copy link

amal007 commented Jul 24, 2015

+1

@jogaco
Copy link

jogaco commented Sep 7, 2015

+1

@amal007
Copy link

amal007 commented Sep 8, 2015

I was able to paginate the elasticsearch results with the below example.

# User Controller
def index
  @records = User.match_all_query(params[:page])
  total_count = @records.response.hits.total
  @records = Kaminari.paginate_array(@records, total_count: total_count)
                                    .page(params[:page])
                                    .per(100)
end


# User Model
def match_all_query(page = 1, per_page = 100)
  page ||= 1
  search({
    query: {
      match_all: {}
     },
     size: per_page,
     from: (page.to_i - 1) * per_page
   })
end


We can then use @records in the view page as <%= paginate @records %>

@jogaco
Copy link

jogaco commented Sep 10, 2015

Thanks for the tip!

@xpepermint
Copy link

+1

1 similar comment
@nflorentin
Copy link

+1

@nflorentin
Copy link

I'd be interested to help with this feature. I'd appreciate any advice on how to implement it without making breaking changes. As far as I understood when calling method search on a repository or a model, the request is done right away and isn't waiting until method results is called. We'd have to change that behaviour right ?

@karmi if you could put me in the right path, that would be great

thanks and sorry for my poor english

@fbarriosCL
Copy link

+1 Hi, I have the same problem(elasticsearch-persistence + kaminari), I will try with the solution of @amal007 🤞

@estolfo
Copy link
Contributor

estolfo commented Oct 17, 2018

I'm going to close this as there is currently support for Kaminari and WillPaginate (and Pagy in progress).

@estolfo estolfo closed this as completed Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants