我刚刚将弹性搜索从2.3.4更新到5.0.1,并将C#nuget包嵌套到最新的2.4.7
我有以下嵌套查询:
SourceFilter sourceFilter = new SourceFilter()
{
Include = Infer.Fields<Page>(p => p.Category, p => p.Title)
};
MultiMatchQuery multiMatchQuery = new MultiMatchQuery()
{
Fields = Infer.Fields<Page>(p => p.Title, p => p.MetaDescription, p => p.Keywords),
Type = TextQueryType.PhrasePrefix,
Query = search.Term
};
var searchQuery = new SearchRequest<Page>()
{
From = search.ResultsFrom,
Size = search.ResultsSize,
Source = sourceFilter,
Query = multiMatchQuery
};
var searchResponse = client.Search<Page>(searchQuery);
我从弹性中得到以下错误:
Deprecated field [include] used, expected [includes] instead
注释掉SourceFilter
可以让查询完成。
使用SourceFilter
有不同的方法吗?
答案 0 :(得分:1)
根据source filtering usage,Include
的语法应为Includes
,而不是Include
。即使您上面提到的错误也简化了Include
的错误语法。我不确定版本兼容性。如果我复制你的,它应该是这样的:
Source = new SourceFilter()
{
Includes = Infer.Fields<Page>(p => p.Category, p => p.Title)
};
答案 1 :(得分:1)
如果您针对Elasticsearch 5.0.1运行you should use a 5.x version of NEST; nuget上的最新5.x版本目前是5.0.0-rc3(预发行版),很快就会推出5.0.0。
5.x contains the Includes
property on ISourceFilter
Kulasangar highlights in his answer。