Restrict search to a list of known objectIDs

Is it possible to “pre-filter” a search to a list of objectIDs? I am looking to search for records by name but only if they also match the given list of IDs.

The following works, but feels very hacky. Especially because there could be up to 1000 objectIDs to match.{
  query: "IPA",
  filters: "objectID:11 OR objectID:12 OR objectID:33 OR objectID:42 OR ..."

Hi @eric2,

The way you utilized filters is indeed the correct way to filter on a known set of ObjectIDs at query time. See for example here

However, depending on your use case you might consider a few other approaches.

  • Do you have an attribute that tracks these large groupings so that you can filter on a more concise value? (e.g., “category: ipa”)

  • Can you organize large groupings into different indices so that you can direct queries to sub-sets of beers? (e.g., direct a query to your “ipa_beers” index or to your “sour_beers” index so that it already focuses on a sub-set of beers)

These are just considerations as Algolia was designed to be fast at query time, but even faster if you structure your data and indices in a way that helps you even before the user starts to search!

Thanks for the help, @ajay.david! Unfortunately I don’t think those two approaches work for us. The filtered objectID array is dynamic, so we can’t group things beforehand.