NEST 弃用字段 [include]

NEST deprecated field [include]

我刚刚将 elasticsearch 从 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);

我从 elastic 返回以下错误:

Deprecated field [include] used, expected [includes] instead

注释掉 SourceFilter 允许查询 运行 通过。

是否有不同的使用方式SourceFilter

根据 source filtering usageInclude 的语法应该是 Includes 而不是 Include。即使是您上面提到的错误也简化了 Include 的错误语法。我不确定版本兼容性。如果我复制你的,它应该看起来像这样:

    Source  = new SourceFilter()
    {
      Includes = Infer.Fields<Page>(p => p.Category, p => p.Title)        
    };

如果您 运行 反对 Elasticsearch 5.0.1,you should use a 5.x version of NEST; the latest 5.x version on nuget is 5.0.0-rc3(预发布),5.0.0 很快就会发布。

5.x contains the Includes property on ISourceFilter that .