Instantsearch.js Stats widget showing wrong values after refinements

As per the title, I’m getting strange stats results when using a refinement widget.

Using latest instantsearch.js v2.2.0.

Strangely, the top most refinement item and bottom-most refinement item show the proper number. Everything in between produces erroneous results.

Here’s a basic Codepen to reproduce:

To reproduce:

  1. Click the top-most refinement item (2016) and the stats widget will match the count in the refinement, as expected.

  2. Click the next refinement item (2015) and the stats widget provides a wrong number.

A quick search through Github Issues didn’t produce anything, so thought I’d start here in case it has something to do with my index itself and not Instantsearch.

A couple of other tidbits of info in case they’re helpful:

  1. Clearing cache does not resolve, but it does change the erroneous values slightly. You can open up the pen in additional browser windows and receive different results for the same refinement.

  2. The index contains 3m+ records. Last time I updated/synced the full dataset it showed an operations count greater than the total record count. I’m not too worried about the operations count (probably an error in my sync script), but thought I’d share in case something screwy is going on with the index’s metadata.

Issue can be reproduced in the Algolia dashboard

Hi Chad,

Thank you for reaching out.

What you’re currently experiencing is the result of an approximation done by the search engine to stay fast including on big indexes like yours: counting the facets is a very expensive operation, (we basically need to browse every matching results one by one). So we browse the beginning of the list, and if the list if very big, we use a rule of three to make an estimation of the counts for the whole results set (more info in our documentation).

There is a flag at the API response level that indicates whether the counts of facet values are approximations or exact: exhaustiveFacetsCount: false (check your network tab).

What we suggest is to indicate to the user that the counts are an approximation by displaying a value that looks like 718,000+ if your exact facet count is 717,505 for instance (you can do so by using a template item).

You can see an example with your data here.

I hope this helps.


Makes perfect sense, thanks for the great explanation.

In my case, the facet values are actually spot on (impressive!). It’s really the stats widget that is causing confusion with potentially large discrepancies (see below).

I suspect my solution may be as simple as hiding the stats widget, as it doesn’t provide much from a UX standpoint anyway in my case.

Label    Facet Count    Stats Count 
2016          97,038         97,038   ✔
2015         717,505      2,446,357   !!!
2014         704,029        416,994
2013         608,445        351,641
2012         508,296        162,147
2011         406,985        225,208
2010         299,942        173,069
2009          34,877         34,877   ✔