2015-03-31 81 views
0

我最近開始使用彈性搜索,我試圖索引一個PDF文檔與映射器附件插件,當索引我打錯誤值不能是空參數名:索引,可有人在解決這個幫助..彈性搜索mapper-attachments,NEST-在索引投擲錯誤

enter image description here

這裏是索引代碼:我猜你忘了你的彈性搜索添加默認索引

static void Main(string[] args) 
    { 

     var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/")); 
     var elasticClient = new ElasticClient(connectionSettings); 

     elasticClient.CreateIndex("pdf-index", c => c.AddMapping<Document>(m => m.MapFromAttributes())); 

     var attachment = new Attachment 
     { 
      Content = Convert.ToBase64String(File.ReadAllBytes("test.pdf")), 
      ContentType = "application/pdf", 
      Name = "test.pdf" 
     }; 

     var doc = new Document() 
     { 
      Id = 1, 
      Title = "test", 
      File = attachment 
     }; 

     elasticClient.Index(doc); 
    } 

    public class Attachment 
    { 
     [ElasticProperty(Name = "_content")] 
     public string Content { get; set; } 

     [ElasticProperty(Name = "_content_type")] 
     public string ContentType { get; set; } 

     [ElasticProperty(Name = "_name")] 
     public string Name { get; set; } 
    } 

    public class Document 
    { 
     public int Id { get; set; } 

     public string Title { get; set; } 

     [ElasticProperty(Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)] 
     public Attachment File { get; set; } 

    } 

回答

0

連接設置。

var uri = new Uri("http://localhost:9200/"); 
var connectionSettings = new ConnectionSettings(uri, defaultIndex: "my-application"); 

var elasticClient = new ElasticClient(connectionSettings);

這裏http://nest.azurewebsites.net/nest/connecting.html

Of'course默認索引的詳細信息是可選的。那麼您必須在索引doc時指定索引。 例如

client.Index(doc, i => i 
    .Index(index) 
    .Type(type)  
);