This content originally appeared on DEV Community and was authored by sugiarto
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 }
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)
This content originally appeared on DEV Community and was authored by sugiarto
sugiarto | Sciencx (2024-09-08T10:15:39+00:00) searchkick get total records. Retrieved from https://www.scien.cx/2024/09/08/searchkick-get-total-records/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.