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 th…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » searchkick get total records." sugiarto | Sciencx - Sunday September 8, 2024, https://www.scien.cx/2024/09/08/searchkick-get-total-records/
HARVARD
sugiarto | Sciencx Sunday September 8, 2024 » searchkick get total records., viewed ,<https://www.scien.cx/2024/09/08/searchkick-get-total-records/>
VANCOUVER
sugiarto | Sciencx - » searchkick get total records. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/08/searchkick-get-total-records/
CHICAGO
" » searchkick get total records." sugiarto | Sciencx - Accessed . https://www.scien.cx/2024/09/08/searchkick-get-total-records/
IEEE
" » searchkick get total records." sugiarto | Sciencx [Online]. Available: https://www.scien.cx/2024/09/08/searchkick-get-total-records/. [Accessed: ]
rf:citation
» searchkick get total records | sugiarto | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.