# In NEST how to make the match query conditional?

**URL:** <https://discuss.elastic.co/t/in-nest-how-to-make-the-match-query-conditional/290178>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 25, 2021, 1:10pm UTC](https://discuss.elastic.co/t/in-nest-how-to-make-the-match-query-conditional/290178 "2021-11-25T13:10:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_Zaman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s_zaman/32/74946_2.png) [@S\_Zaman](https://discuss.elastic.co/u/S_Zaman)\
**Post date:** [November 25, 2021, 1:10pm UTC](https://discuss.elastic.co/t/in-nest-how-to-make-the-match-query-conditional/290178/1 "2021-11-25T13:10:52Z")

</div>

How to make the match conditionally added/removed in c# .NET NEST?

```auto
var response = client.Search<Tweet>(s => s
    .Index("mytweetindex") //or specify index via settings.DefaultIndex("mytweetindex");
    .From(0)
    .Size(10)
    .Query(q => q
        .Term(t => t.User, "kimchy") || q
        .Match(mq => mq.Field(f => f.User).Query("nest"))
        .Match(mq => mq.Field(f => f.UserLocation).Query("NY")) //if UserLocation was supplied only than add this .Match Line.
    )
);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 23, 2021, 1:11pm UTC](https://discuss.elastic.co/t/in-nest-how-to-make-the-match-query-conditional/290178/2 "2021-12-23T13:11:38Z")

</div>

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