Limiting and sorting via tags


We’ve been using Algolia on our e-commerce site for a while now, but we used 3 different indices to cater for the different content (FAQ, categories and products). I’ve combined these 3 indices into one, using tags to differentiate the different content. I’m using this index for both the regular search and the autocomplete, but I’ve got trouble limiting and sorting the results to my liking.

What we have now (V3, multiple indices) is 5 FAQ and 5 category results and an unlimited amount of products. But I can’t figure out how to get this done with one index using tags (and using V4).

Can anyone point me in the right direction on this?

Thanks in advance!


Hi Robert, welcome to the forum! If I’m understanding correctly, you’d like to pull 5 FAQ results, 5 category results and unlimited product results. Whether or not you use one index or 3, this will require three separate queries.

For the separate indices model, of course one request will be made to each index. If you’ve put all of the different types together, you’ll need to make three separate requests to the same index, with different parameters {filters: “tag:FAQ”, hitsPerPage: 5}, {filters: “tag:category”, hitsPerPage: 5}, {filters: “tag:product”, hitsPerPage: 20}.

For that reason, and for reasons of relevance (there may be different searchableAttributes, customRanking metrics, etc. for the different data types) it might be best to actually stick with the three separate indices. Multi-index search is well supported in v4; here are the docs for that in case you hadn’t seen them:

I hope this helps!

Hi Maria, thanks for the quick reply. I see what you mean and I will dive into multi-index searches to see if I can get it to work properly! :smile: