Global filter or limit

Hello, I want to ask if you can limit the searchable result with some “global filter / limit” setting.

My index “products” looks like:

“Hidden”: 0,
“Name”: “Product 1”
“Hidden”: 1,
“Name”: “Product 2”

I am wondering if I can set somewhere in dashboard that all search is limited to only items with hidden = 0. I’m new to Algolia so sorry is common task.

Thanks for reply.

Hi, you can use numeric filters to achieve what you want: Filtering | Algolia

Here’s an example using JavaScript:{
  filters: 'stock_quantity > 0'

This is also doable with the dashboard but it will require you to duplicate your index if you want both hidden = 0 and hidden = 1 at a certain time.

Maybe you can give us your actual usecase behind such question? Your business requirement basically.


Thanks you for reply.

I know I can do it in javascript. But from front app I never want search for products which are hidden. I dont know if I can setup it globally in Algolia Dashboard.

In my app the admins can create products. They have option to hide product where I only send partialUpdateObject to Algolia a set up hidden field to 1, because I dont want delele whole object.

Ok then what you can do is generate a specific API key that will have the numeric filter being set by default and can’t be overloaded.

Example (using Node.js):

var client = algoliasearch(appId, searchOnlyAPIKey);
var restrictedAPIKey = client.generateSecuredAPIKey(searchOnlyAPIKey, {filters: 'Hidden = 0'});

Then you would use that restrictedAPIKey on your frontend and nobody will be able to display hidden objects nor overload this parameter. This specific API key will be a secure way to do searches.

Does that answer your need?

Thank you for your advice. I do try this.