# How to implement Filters with ElasticSearch 7 and NEST 7

**URL:** <https://discuss.elastic.co/t/how-to-implement-filters-with-elasticsearch-7-and-nest-7/235166>\
**Category:** Elasticsearch\
**Created:** [June 1, 2020, 12:46pm UTC](https://discuss.elastic.co/t/how-to-implement-filters-with-elasticsearch-7-and-nest-7/235166 "2020-06-01T12:46:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isanka\_Thalagala](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/isanka_thalagala/32/54562_2.png) [@Isanka\_Thalagala](https://discuss.elastic.co/u/Isanka_Thalagala)\
**Post date:** [June 1, 2020, 12:46pm UTC](https://discuss.elastic.co/t/how-to-implement-filters-with-elasticsearch-7-and-nest-7/235166/1 "2020-06-01T12:46:51Z")

</div>

I'm using ElarsticSearch 7.7 & NEST 7.7 and I'm trying to filter data by some fields.  
As of 1st try, I need to filter by delivery dates.

it returns documents by the search query.But when I add **deliveryFilter**  
I'm getting 0 documents and it should be 2.

> ```
> var deliveryFilter = new TermQuery { Name = "Delivery Date Filter", Field = Field<ElasticIndexGroupProduct>(p => p.DeliveryDateName), Value = "3-5 days" };
> queryContainer &= deliveryFilter; // it is working without this line
> 
> ```

It's working fine without this filter. But I need filter by DeliveryDateNames

> ```
> public SearchResult Search(string searchQuery, int storeId, int pageNumber = 1, int pageSize = 10, IList<SearchFilter> requestFilter = null, decimal? priceFrom = null, decimal? priceTo = null, string sortBy = null)
> {
> //------ test data----------------------------
> searchQuery = "Nikon";
> priceFrom = 0;
> priceTo = 6550000;
> pageNumber = 1;
> pageSize = 12;
> sortBy = "z-a";   
> 
> var queryContainer = new QueryContainer();
> 
> #region MyRegion
> 
> var multiMatch = new QueryStringQuery
> {
> Fields = Infer.Field<ElasticIndexGroupProduct>(p => p.Name)
> .And(Infer.Field<ElasticIndexGroupProduct>(p => p.CategoryName))
> .And(Infer.Field<ElasticIndexGroupProduct>(p => p.AssociatedProducts.Select(x => x.Name))),
> Boost = 1.1,
> Name = "named_query",
> Query = searchQuery,
> DefaultOperator = Operator.Or,
> Analyzer = "standard",
> QuoteAnalyzer = "keyword",
> AllowLeadingWildcard = true,
> MaximumDeterminizedStates = 2,
> Escape = true,
> FuzzyPrefixLength = 2,
> FuzzyMaxExpansions = 3,
> FuzzyRewrite = MultiTermQueryRewrite.ConstantScore,
> Rewrite = MultiTermQueryRewrite.ConstantScore,
> Fuzziness = Fuzziness.Auto,
> TieBreaker = 1,
> AnalyzeWildcard = true,
> MinimumShouldMatch = 2,
> QuoteFieldSuffix = "'",
> Lenient = true,
> AutoGenerateSynonymsPhraseQuery = false
> };
> //queryContainer &= multiMatch;
>        
> #endregion
> 
> var deliveryFilter = new TermQuery { Name = "Delivery Date Filter", Field = Field<ElasticIndexGroupProduct>(p => p.DeliveryDateName), Value = "3-5 days" };
> queryContainer &= deliveryFilter; // it is working without this line
> 
> var searchRequest = new SearchRequest<ElasticIndexGroupProduct>()
> {
> Profile = true,
> From = (pageNumber - 1) * pageSize,
> Size = pageSize,
> Version = true,               
> Query = new BoolQuery
> {
> Must = new QueryContainer[] { multiMatch },
> Filter = new QueryContainer[] { queryContainer }
> }
> };
> var searchResponse = _client.Search<ElasticIndexGroupProduct>(searchRequest);
> 
> ```
> 
> }

---

<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:** [June 29, 2020, 12:46pm UTC](https://discuss.elastic.co/t/how-to-implement-filters-with-elasticsearch-7-and-nest-7/235166/2 "2020-06-29T12:46:56Z")

</div>

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