ElasticSearch and Nest filtering does not work

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.
For more options, visit https://groups.google.com/groups/opt_out.

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:

http://www.elasticsearch.org/guide/reference/query-dsl/missing-filter/

Which in NEST you can do as such:

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 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.
For more options, visit https://groups.google.com/groups/opt_out.