简体   繁体   中英

Add() method not found in NEST 2.0

This is my NEST2.0 POCO declaration:

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

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. This issue has a really nice description, so please take a look.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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