If you're seeing approximate hit counts in your search results and wondering how to make them more accurate, understanding the role of the facets parameter is key. This article explains how it impacts hit count exhaustivity and why it's not always recommended to use it in every request.
When facets is not used
By default, if a query doesn’t require faceting, the Algolia engine is optimized for speed. It may return an approximate hit count rather than an exhaustive one. This is because the engine stops counting after retrieving enough relevant results, typically those with the highest match and proximity scores (e.g., over 10,000). In such cases:
nbHitsis an estimateexhaustiveNbHitsis set to false
This is intentional, allowing for faster performance when exact counts aren't necessary.
When facets is used
Including the facets parameter, especially facets: ["*"], instructs the engine to skip certain optimizations and perform a more thorough scan of the index. This can result in:
An exhaustive hit count (
exhaustiveNbHits: true)More accurate facet value counts
This is useful when you need precise results, such as for reporting, analytics, or when building complex faceted navigation.
Why not use facets: ["*"] all the time?
While it may be tempting to include the facets parameter on all search requests to ensure accuracy, this can significantly impact search performance, particularly on large datasets. Thorough scans require more resources and lead to slower response times.
In most use cases, approximate counts are sufficient and much faster. Therefore, it's best to include facets only when needed, such as when:
You need to display facet values
Exact counts are required for the experience
You're debugging or validating data
Still seeing inconsistencies?
There are other factors that can cause incorrect or inconsistent hit or facet counts. If this article doesn’t resolve your issue, refer to this guide:
Facet and hit count issues checklist