# ElasticSearch and Nest filtering does not work

**URL:** https://discuss.elastic.co/t/elasticsearch-and-nest-filtering-does-not-work/12710
**Category:** Elasticsearch
**Created:** [July 9, 2013, 6:00am UTC](https://discuss.elastic.co/t/elasticsearch-and-nest-filtering-does-not-work/12710 "2013-07-09T06:00:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Aref\_Karimi](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Aref\_Karimi](https://discuss.elastic.co/u/Aref_Karimi)
#### Post date: [July 9, 2013, 6:00am UTC](https://discuss.elastic.co/t/elasticsearch-and-nest-filtering-does-not-work/12710/1 "2013-07-09T06:00:12Z")

</div>

run a query that returns 10 results. There is a property in my document  
called Type. The value of this property for some records is an empty string  
and for some other records is either "AudioAlbum" or "AudioRington".

I want to do two things: 1- Exclude the documents that their Type property  
does not have a value from the search result. 2- Get AudioAlbums only (as a  
different search).

My search code for getting AudioAlbums is this:

var docs = client.Search(  
b =\> b.Type("content").Query(q =\> q.Fuzzy(fz =\> fz.OnField("title").Value(keyWord).OnField("artists.name"))).Filter(x =\> x.Term("type", "AudioRingtone"))).Documents.ToList();

Without the Filter extension method I get 10 records (including two AudioAlbums). when I add the .Filter method I get zero records.

Also I want to exclude the records whose Type property does not have a value. Again my code (given below) does not record any results:

BaseFilter notFilter = Filter.Not(x =\> Filter.Term("Type", string.Empty));  
var docs = client.Search(  
b =\>  
b.Type("content")  
.Query(q =\> q.Fuzzy(fz =\> fz.OnField("title").Value(keyWord).OnField("artists.name"))).Filter(notFilter)).Documents.ToList();

What's wrong with my code?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Martijn\_Laarman\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman_2/32/2033_2.png) [@Martijn\_Laarman\_2](https://discuss.elastic.co/u/Martijn_Laarman_2)
#### Post date: [July 9, 2013, 2:01pm UTC](https://discuss.elastic.co/t/elasticsearch-and-nest-filtering-does-not-work/12710/2 "2013-07-09T14:01:31Z")

</div>

Hi,

In your first example you filter on the field "type" and in the second on  
the "Type" I suppose you need to change the first to "Type".

Depending on your analysis for the "Type" field you might also need to  
lowercase "AudioRingtone" too.

In the second example you are using the wrong query:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Which in NEST you can do as such:

[https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Search/Filter/Singles/MissingFilterJson.cs](https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Search/Filter/Singles/MissingFilterJson.cs)

If you issue an empty term filter/query you hit NEST conditionless query  
logica, and nest will infact not even send the filter at all.

See [http://nest.azurewebsites.net/concepts/writing-queries.html](http://nest.azurewebsites.net/concepts/writing-queries.html) for help  
using the query dsl.

On Tuesday, July 9, 2013 8:00:12 AM UTC+2, Aref Karimi wrote:

> run a query that returns 10 results. There is a property in my document  
> called Type. The value of this property for some records is an empty string  
> and for some other records is either "AudioAlbum" or "AudioRington".
> 
> I want to do two things: 1- Exclude the documents that their Type property  
> does not have a value from the search result. 2- Get AudioAlbums only (as a  
> different search).
> 
> My search code for getting AudioAlbums is this:
> 
> var docs = client.Search(  
> b =\> b.Type("content").Query(q =\> q.Fuzzy(fz =\> fz.OnField("title").Value(keyWord).OnField("artists.name"))).Filter(x =\> x.Term("type", "AudioRingtone"))).Documents.ToList();
> 
> Without the Filter extension method I get 10 records (including two AudioAlbums). when I add the .Filter method I get zero records.
> 
> Also I want to exclude the records whose Type property does not have a value. Again my code (given below) does not record any results:
> 
> BaseFilter notFilter = Filter.Not(x =\> Filter.Term("Type", string.Empty));  
> var docs = client.Search(  
> b =\>  
> b.Type("content")  
> .Query(q =\> q.Fuzzy(fz =\> fz.OnField("title").Value(keyWord).OnField("artists.name"))).Filter(notFilter)).Documents.ToList();
> 
> What's wrong with my code?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 2:27am UTC](https://discuss.elastic.co/t/elasticsearch-and-nest-filtering-does-not-work/12710/3 "2017-07-06T02:27:28Z")

</div>


