8

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?

Nicolas Blanco
  • 11,164
  • 7
  • 38
  • 49

3 Answers3

12

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)' });
redox
  • 2,269
  • 13
  • 22
1

For me it wasn't working with '=' but with ':', meaning:

{ filters: 'choice_ids:1 OR choice_ids:99 OR choice_ids:100 OR choice_ids:200' })
0

For me, neither of @Léo Chaz Maltrait or @redox answers worked. I had to format mine like:

{ filters: '(choice_ids:"1") OR (choice_ids:"99" OR (choice_ids:"100") OR (choice_ids:"200"))' })

I am also using algoliasearch npm package.

Jwags
  • 474
  • 6
  • 15