【问题标题】:Add() method not found in NEST 2.0在 NEST 2.0 中找不到 Add() 方法
【发布时间】:2016-03-01 10:13:30
【问题描述】:

这是我的 NEST2.0 POCO 声明:

[ElasticsearchType(Name = "MyDocument")]
public class MyDocument: DynamicResponse
{
    [String(Store = false, Index = FieldIndexOption.NotAnalyzed)]
    public string HistoryId{ get; set; }

    [String(Store = false, Index = FieldIndexOption.NotAnalyzed)]
    public string FileId { get; set; }

    [Date(Store = false)]
    public DateTime DateTime { get; set; }
}

这是它的映射:

            elastic.Map<MyDocument>(m => m
                .Index(indexName)
                .AutoMap().AllField(a => a.Enabled(false))
                .Dynamic()
                .DynamicTemplates(dt => dt
                    .Add(t => t
                        .Name("pv_values_template")
                        .Match("ch_*")
                        .Mapping(m2 => m2
                            .Number(n => n
                                .Store(false)
                                .Index(NonStringIndexOption.NotAnalyzed)
                                .DocValues(true))))));

看起来.Add() 方法不再存在(它在 NEST 1.0 中运行良好)

【问题讨论】:

    标签: c# .net elasticsearch nest nest2


    【解决方案1】:

    Add 方法已重命名为 DynamicTemplate 并且签名有所改变,请看一下:

    client.Map<Document>(m => m
        .Index(indexName)
        .AutoMap().AllField(a => a.Enabled(false))
        .Dynamic()
        .DynamicTemplates(dt => dt
            .DynamicTemplate("pv_values_template", t => t 
                .Match("ch_*")
                .Mapping(m2 => m2
                    .Number(n => n
                        .Store(false)
                        .DocValues(true))))));
    

    您可能会问.Index(NonStringIndexOption.NotAnalyzed) 选项在新映射中的位置。 This issue 有一个非常好的描述,所以请看一下。

    希望对你有帮助。

    【讨论】:

    猜你喜欢
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    相关资源
    最近更新 更多