searchkick get total records
sugiarto

sugiarto @ugifractal

About: I am a Freelance ruby on rails developer. I help startup, professional and hobbyist solve problem.

Location:
Cimahi, Indonesia
Joined:
May 14, 2021

searchkick get total records

Publish Date: Sep 8 '24
1 0

In one of my projects, I used searchkick gem and elasticsearch for implementing search feature.

Something weird happens when database records are over 10K records. The total records always show 10K, even though the actual records are 267K.

I fixed this issue by adding

body_options: { track_total_hits: true }
Enter fullscreen mode Exit fullscreen mode

As an argument for the search method.

Here is an example

collections = MyModel.pagy_search(query, fields: [:name], load: false, body_options: { track_total_hits: true })
pagy, properties = pagy_searchkick(collections)
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment