2017-04-20 99 views
0

我一直在嘗試使用批量插入功能,但每次使用它都會顯示一些映射錯誤。批量插入函數聲明已經從嵌套1.x更改爲嵌套5.x,因爲在5.x嵌套文檔中我沒有找到.bulk()函數。請推薦elasticsearch的批量插入嵌套5.x

代碼BULK INSERT:

 public void bulkInsert(List<BaseData> recordList, List<String> listOfIndexName) 
    { 

      BulkDescriptor descriptor = new BulkDescriptor(); 
      descriptor.Index<BaseData>(op => op 
       .Document(recordList[j]) 
       .Index(listOfIndexName[j]) 

       ); 


     } 

     var result = clientConnection.Bulk(descriptor); 


    } 

我,我傳遞數據的列表看起來是這樣的:

[ElasticsearchType(IdProperty = "number")] 


class TicketData : BaseData 
{   
    //[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)] 


    [Date(Name = "sys_updated_on", Store = true)] 
    public DateTimeOffset sys_updated_on { get; set; } 


     [Text(Name = "number", Store = true)] 
    public override string number { get; set; } 


    [Text(Name = "incident_state", Store = true)] 
    public string incident_state { get; set; } 


    [Text(Name = "location", Store = true)] 
    public string location { get; set; } 


    [Text(Name = "assigned_to", Store = true)] 
    public string assigned_to { get; set; } 



[Text(Name = "u_knowledge_id", Store = true)] 
    public string u_knowledge_id { get; set; } 


    [Text(Name = "u_knowledge_id.u_process_role", Store = true)] 
    public string u_knowledge_id_u_process_role { get; set; } 

}

+0

而錯誤是? –

+0

該解決方案可能對您有所幫助。 http://stackoverflow.com/questions/22017858/how-to-bulk-insert-json-using-nest-elasticsearch 或者你可以參考這個,從這個鏈接你可以得到更多關於批量插入的基本想法謝謝! –

+0

您看起來像是在示例中缺少代碼什麼是'描述符'?你能編輯你的問題來添加那個細節嗎?另外,映射錯誤是什麼? Elasticsearch返回什麼錯誤?大容量請求json是什麼樣的? –

回答

2

似乎NEST不能推斷因爲您指定了泛型類型BaseData,而實際類型爲TicketData。你應該指定你想索引的實體類型。

descriptor.Index<BaseData>(op => op 
    .Document(recordList[j]) 
    .Index(listOfIndexName[j]) 
    .Type(recordList[j].GetType()) 
); 

目前查詢試圖動態創建一個不同類型的默認映射,而不是將其解釋爲現有的類型有明確的映射:既然你可以有你的名單內的不同類型,可以使用GetType()方法得到的實際類型

+0

否仍然給出了同樣的錯誤 – Nilanjana

+0

誤差isDebugInformation從內置\t'」無效NEST響應一個成功的低級調用POST:/ _bulk \ r \ n#無效批量項目:\ r \ n操作[0]:索引返回400 _index:datd.ticketlog01-2017.15 _type:ticketdata _id:IN1 _version:0錯誤:Type :illegal_argument_exception原因:\「無法將非對象映射[u_knowledge_id]與對象映射[u_kno wledge_id] \「CausedBy:\」\「\ r \ n operation [1]:index returned 400 _index:datd.ticketlog01-2016.30 _type:ticketdata' – Nilanjana

+0

看起來像一個字段類型與其他對象類型的衝突。你還有其他什麼映射? – Random