Nested filter by one item from array not every

Hello, I have index of products, each product has variants. I am trying to filter by attributes of variants. Structure of product looks like:

{
  name: 'T-Shirt',
  variants: [
    { color: 'red', size: 'M' },
    { color: 'blue', size: 'L'}
  ]
}

Now, I am trying to filter products with color - red & size - L - I am getting T-Shirt because it has one variant with color red and another variant with size L. Unfortunately, I expect to get only products which has one variant that is both red and L.

I am sending a query with parameters like:

// ...
facetFilters: ["variants.color:red", "variants.size:L"],
facets: ["variants.color", "variants.size"]

I see that facets are also computed badly - in the same manner as results. Do you have an idea how to force values to be present in one object inside nested array?

Hi @fjedrasik

Have you tried filters?

Using the example Algolia provides you would have something like

index.search('T-Shirt', {
  filters: 'variants.color:red AND variants.size:L'
}).then({ hits } => {
  console.log(hits);
});

Yes, I did. Unfortunately, it behaves same as I’ve described above

Ok, I’ve solved it with these:

2 Likes