2016-03-01 64 views
0

沒有發現這是我NEST2.0 POCO聲明:Add()方法中NEST 2.0

[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工作正常)

回答

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有一個非常好的描述,所以請看看。

希望它有幫助。

+0

Thanks @Rob。這部分解決了我的問題。使用批量寫入編寫這些文檔時,我仍然遇到一些問題。請看看這裏:http://stackoverflow.com/questions/35721566/bulk-write-on-elasticsearch-2-0-nest-2-0-throws-a-stackoverflow-exception –

+0

我剛剛添加了一個編輯我的問題在這裏:http://stackoverflow.com/questions/35721566/bulk-write-on-elasticsearch-2-0-nest-2-0-throws-a-stackoverflow-exception –