Elastic cannot filter out only some variants without removing all from result

Ni,

I am trying to get an exclude filter working.
I am a bit unfamiliar with the ways the queries are built but I used the tags query already existing and used MustNot instead of Should (see below)

Issue is that if it matches on 1 variant of many on a product it will exclude that product. I only want it to remove said variant from result. If all variants are matched then it wont display the product on the category page.

Currently testing with a TextOption field where you can set different values in BO and based on that filter it out if needed.

Any ideas what could be wrong? Also thanks in advance.

                if (excludeTags != null)
                {
                    foreach (var excludeTag in excludeTags.Where(x => x.Value.Count > 0))
                    {
                        var filterTags = excludeTag.Value
                            .Select<string, Func<QueryContainerDescriptor<ProductDocument>, QueryContainer>>(tagValue =>
                                s => s
                                    .Nested(n => n
                                        .Path(x => x.Tags)
                                        .Query(nq
                                            => nq.Term(t => t.Field(f => f.Tags[0].Key).Value(excludeTag.Key))
                                               && nq.Term(t => t.Field(f => f.Tags[0].Value).Value(tagValue))
                                        )
                                    ));
                        allQueries.Add(qc.Bool(b => b.Filter(bf => bf.Bool(bb => bb.MustNot(filterTags)))));
                    }
                }

Litium version: 7.6.1

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.