When using the "facetingAfterDistinct" parameter, there may be inconsistent results shown in facet counts in a refinement list. For example, a facet may have a count of 2 for a specific facet value. However when selecting the refinement, there are "extra" hits returned:
This occurs due to how the counts are initially calculated with facetingAfterDistinct set to true at query time. It is expected behavior covered in our docs page here:
https://www.algolia.com/doc/api-reference/api-parameters/facetingAfterDistinct/#usage-notes
What's happening is an initial calculation of facet counts prior to any refining of the results, but after being deduplicated using the index's configured "distinct" attribute. Therefore each unique attribute value adds to the facet count total(s) using its top pre-refinement result. If there are different result rankings between these unique values--due to different facet values elsewhere on the record-- the results will be inconsistent.
For the the above example let's say the configured "distinct" attribute was "id." There would have been 3 unique values for "id" after deduplication, but only 2 of them had their top result contain "toddler" for the "options.size" attribute. The third "id" value had a more highly ranked record that contained a different size. Therefore, the count was "2" for "toddler" when initially totaling with facetingAfterDistinct=true, but when selecting the size refinement it displays all 3 options.