DEV Community

sugiarto
sugiarto

Posted on

1

searchkick get total records

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

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Retry later