ElasticSearch和巢过滤不起作用 [英] ElasticSearch and Nest filtering does not work
问题描述
我运行,返回10个结果的查询。有一个叫类型在我的文档属性。 。这个属性对于某些记录的值是一个空字符串和一些其他的记录或者是AudioAlbum或AudioRington
I 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".
我想要做的两件事情:1 - 排除其类型属性没有从搜索结果的值的文件。 。2 - 只有获得AudioAlbums(如不同的搜索)
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).
获取AudioAlbums我的搜索代码是这样的:
My search code for getting AudioAlbums is this:
var docs = client.Search<content>(
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();
不使用滤镜扩展方法,我得到10条(其中包括两个AudioAlbums)。当我添加了.Filter方法,我得到的零记录。
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<content>(
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?
推荐答案
粘贴答案从elasticsearch用户列表
在你的第一个例子中,你在球场上筛选复制类型,并在上第二个型我想你需要改变第一个类型。
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".
根据您的分析,为类型字段,你可能还需要小写的AudioRingtone过。
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/
其中在NEST你可以做这样:
Which in NEST you can do as such:
如果您发出一个空长期过滤器/查询你打NEST conditionless查询逻,和鸟巢将INFACT甚至没有在所有发送的过滤器。
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.
请参阅的http://窝.azurewebsites.net /窝/写入queries.html 使用查询DSL帮助。
See http://nest.azurewebsites.net/nest/writing-queries.html for help using the query dsl.
这篇关于ElasticSearch和巢过滤不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!