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

**URL:** <https://forum.litium.com/t/elastic-cannot-filter-out-only-some-variants-without-removing-all-from-result/2041>\
**Category:** Questions\
**Tags:** search, litium-7\
**Created:** [May 4, 2021, 8:24am UTC](https://forum.litium.com/t/elastic-cannot-filter-out-only-some-variants-without-removing-all-from-result/2041 "2021-05-04T08:24:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/artur/32/948_2.png) [@Artur](https://forum.litium.com/u/Artur)\
**Post date:** [May 4, 2021, 8:24am UTC](https://forum.litium.com/t/elastic-cannot-filter-out-only-some-variants-without-removing-all-from-result/2041/1 "2021-05-04T08:24:43Z")

</div>

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.

```auto
                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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [June 1, 2021, 8:25am UTC](https://forum.litium.com/t/elastic-cannot-filter-out-only-some-variants-without-removing-all-from-result/2041/2 "2021-06-01T08:25:23Z")

</div>

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