Negating results by a keyword included in an array

Dear Algolia community,

I am trying to create a search system for users to search for processed foods by category and filter it by their contents of ingredients which is stored as an array.
For example if a user wants to search for a chip that doesn’t contains salt, Algolia would go through
the ingredients list for each products (Chips) and returns the results that doesn’t contain salt. In the example below being product 2.
Basically shows chips that doesn’t contain salt and hides results that does contain salt.

Product1:
ingredients:[salt,xxx,yyy,zzz,bluh,bluh]
Product2:
ingredients:[xxx,yyy,zzz,bluh,bluh] (no sult)

I was wondering how I could perform such task , if even possible.
One option I thought about was to use Negation in FacetFilter however, not really sure if this can be used in an array.
Note: the filter keywords may be multiple as well.
Thank you.

In order to do this type of negation, you would have to construct a filter and inject it into your search, either using the API or a <Config> widget.

You might be able to do this with custom components, but it starts to feel a lot like querying a database at that point. And I can’t think of a good way to do this type of exclusive filtering using refinement widgets.

If the number of ingredients people are trying to avoid is finite, It would be much easier to perform the inversion programmatically as you create the records – add an attribute called excludedIngredients that lists all of the things you’d want to filter against:

Product1:
  ingredients:[salt,xxx,yyy,zzz,bluh,bluh],
  excludedIngredients: [sugar, gluten]
Product2:
  ingredients:[xxx,yyy,zzz,bluh,bluh],
  excludedIngredients: [salt, sugar, gluten]

Then you could use a simple refinementList since salt is now a positive filter against your excludedIngredients attribute.