Is it possible to get the exact number of hits? #1264
-
Hi everyone! I want to get a total number of documents for each query (not the estimate of 10000). Normally I achieved this by using setting "track_total_hits" to true, but this doesn't seem to work for Searchkit? I've tried to redefine getQuery as follows:
This didn't work for me though, am I missing something or is it impossible currently? Thank you in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi there! Its possible but you need to use The difference between https://www.searchkit.co/docs/api-documentation/searchkit#beforesearch-hook-function Something like client = SearchkitInstantsearchClient(sk, {
hooks: {
beforeSearch: async (searchRequests) => {
return searchRequests.map((sr) => {
return {
...sr,
body: {
...sr.body,
track_total_hits: true
}
}
})
}
}
}) |
Beta Was this translation helpful? Give feedback.
hi there!
Its possible but you need to use
beforeSearch
request hook instead to pass intrack_total_hits
to each request.The difference between
getQuery
andbeforeSearch
hooks is thatbeforeSearch allows you to modify the whole request.
getQuery` is for those who want to adjust only the relevance of the organic query.https://www.searchkit.co/docs/api-documentation/searchkit#beforesearch-hook-function
Something like