Wired behaviour with the distinct setting and different between filters & facet filters

Hi,

We have a product index, there are some attribute such as sku, department, supplier, brand, region.

I want it to be filtered always by region. so I use the Configure react component, add pass in the filters parameter as:
region:AU.

The wired thing is that I get different count every time I make a new request. Then I found the distinct settting is true and it was set to sku. I tried two options: set distinct to false; or set attributeForDistinct to objectID. Both of these two options fixed my issue.

Another approach I tried is to use the facetFilters in Configure component, which works well even I keep distinct to true and attributeForDistinct to sku.

So I have questions:

  1. why the filters behaves diffierent with facetFilters for the same attribute.
  2. why it returns different count everytime if I am using the distinct feature and with filter region:AU, it might be a data issue, but for the same request, I think it should return the same result and count always.

I can’t share the index as it’s confidential. if it’s difficult to know the exact problem, any direction for investigation is also appriciated.

Thanks.

Hi there!

The distinct parameter is useful when you want to only retrieve a limited amount of records for a given attribute. If attributeForDistinct is set to sku, you’ll only get one result maximum per sku, even if several of your Algolia records share the same sku.

In that sense, it’s useless to set attributeForDistinct to objectID, because all your records have a unique objectID. You’re better off disabling distinct altogether.

The filters and facetFilters parameters should behave the same. There can be any number of reasons why you’re experiencing differences for the same query, depending on the other settings you have set, or the size of your index.

Since you can’t share the index, here’s what I’d recommend to investigate:

  1. Create a brand new index via the Algolia dashboard, and don’t alter the settings.
  2. If your index is large, index a subset of your current index (50-100 records should do it) in the new one.
  3. Set the attribute region in attributesForFaceting (you can do it in the dashboard in Configuration > Filtering and Faceting).
  4. Back on the explorer (Browse), click the Add Query Parameter button and set region:AU in the facet filters field, then apply the changes and try a query.
  5. Click again on Add Query Parameter, remove the facet filters, go to Custom and paste the following JSON: { "filters": "region:AU" }, then apply the changes, try a query and compare.

Let us know how it goes!