简体   繁体   English

在NEST 2.0中找不到Add()方法

[英]Add() method not found in NEST 2.0

This is my NEST2.0 POCO declaration: 这是我的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; }
}

and this is the mapping for it: 这是它的映射:

            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))))));

Looks like the .Add() method doesn't exist anymore (it was working fine with NEST 1.0) 看起来.Add()方法不再存在(与NEST 1.0配合正常)

Add method has been renamed to DynamicTemplate and signature changed a bit, so take a look: 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))))));

Probably you are asking where is .Index(NonStringIndexOption.NotAnalyzed) option in the new mapping. 可能是您在问新映射中的.Index(NonStringIndexOption.NotAnalyzed)选项在哪里。 This issue has a really nice description, so please take a look. 这个问题的描述非常好,因此请看一看。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM