Search code examples
algolia

Algolia filter equivalent to SQL IN for arrays?


I've got records in Algolia containing an array attribute with integer values, like :

{
  ...
  choice_ids: [1, 99, 100, 200]
  ...
}

I want to filter all records containing any value of another array. For example I search for [1, 300, 400, 600, 700], I should get the record on top because it contains 1.

Should I construct the filter with OR arguments or is there a better way?


Solution

  • Should I construct the filter with OR arguments or is there a better way?

    Yes that's the way to go.

    index.search('....', { filters: '(choice_ids=1 OR choice_ids=99 OR choice_ids=100 OR choice_ids=200)' });