Numeric Refinement List does not work on one specific facet

I’m having a really strange issue. I have two numeric facets that I would like to filter on using numeric refinement lists. One works just fine. The other seems to break the widget completely.

I have a code example, but would rather not make it public as it connects to my Algolia index. Please advise on how to share. In the meantime, I can give some pictures.

Expected behavior: when clicking an option, that option becomes selected and the previous selection becomes unselected. The data then updates accordingly.

Actual behavior: new radio buttons have their dot filled in but no other functions are performed.

image

Hi @kevin2,

Thanks for contacting Algolia!

As an aside, if you use our front-end InstantSearch libraries the information such as your AppID, Search API Key, and index name are all publicly available in the network request. Only if you use a back-end search will that information be hidden.

To better assist you would you be able to replicate your issue with minimum reproducible code in this Sandbox? https://codesandbox.io/s/qvj3zrqmr6

Thanks!

Okay. Here you go: https://codesandbox.io/s/5w6p9vm6on

Hey @kevin2,

The issue seems to be coming from the Algolia API saying: invalid numeric attribute(sleeps), attribute not specified in numericAttributesForFiltering setting. Could you give access to Algolia support to look at your dashboard? I think there might be something different between the sleeps attribute and the slides attribute.

It could also be possible that sleeps isn’t always a number (sometimes a string).

Thanks

Sure thing, access has been granted.

I checked the way we’re updating Algolia, and sleeps should always be an integer.

The error message is helpful, though. I did not check the console on codesandbox for the error because my version of the code hasn’t been throwing any errors. Is there any reason you can think of for this? It would obviously be very helpful to see error messages!

Hi @kevin2,

The error is not thrown at the InstantSearch level but at the client level. You can see the error inside the “Network” panel of the DevTools extension. You can also catch the error with InstantSearch with the following code:

const search = instantsearch({ ... });

search.on("error", err => {
  console.log(err);
});

Like @haroen said the issue come from the fact that the attribute sleeps is not available for numerical filters. This setting is controlled by numericAttributesForFiltering. By default, the value is null and all numeric attributes are automatically indexed and available as numerical filters. But in your case there is a list of attributes that are whitelisted for numerical filters. Here is the non exhaustive list of those attributes:

{
  numericAttributesForFiltering: [
    "equalOnly(link_id)",
    "equalOnly(approved)",
    "equalOnly(status)",
    "equalOnly(new)",
    "equalOnly(isdealer)",
    "equalOnly(under_nada)",
    // ...
  ];
}

To retrieve the full list you can perform a getSettings call on your index. Here is how to achieve this:

const algoliasearch = require('algoliasearch');

const client = algoliasearch('APP_ID', 'API_KEY');
const index = client.initIndex('INDEX_NAME');

index.getSettings().then(res => {
  console.log(
    'numericAttributesForFiltering:',
    JSON.stringify(res.numericAttributesForFiltering, null, 2)
  );
});

You should be able to solve your issue by adding the feeds attribute to the list of numericAttributesForFiltering. You can use the setSettings method to configure it.

Hope that helps, let me know if you have questions.

3 Likes