2015-06-18 43 views
0

在我的ElasticSearch數據庫上,我需要從插入查詢(我正在使用.NET C#)中獲取自動生成的ID。怎麼做?我試着調試readRecords響應,但我沒有找到這樣的ID。ElasticSearch - 如何從插入查詢中獲取自動生成的ID

基本上我需要相當於MySQL LAST_INSERT_ID()的命令。

var readRecords = elasticClient.Search<HistoryRecord>(s => s 
       .Index(elasticIndexName) 
       .Filter(f => 
        f.Term(t => t.MacAddr, historyRecord.MacAddr) && 
        f.Term(t => t.GroupName, historyRecord.GroupName) && 
        f.Term(t => t.GroupNo, historyRecord.GroupNo) && 
        f.Term(t => t.InstrType, historyRecord.InstrType) && 
        f.Term(t => t.InstrumentAddress, historyRecord.InstrumentAddress) && 
        f.Term(t => t.InstrumentName, historyRecord.InstrumentName) && 
        f.Term(t => t.UhhVersion, historyRecord.UhhVersion))).Documents 

回答

2

你可以找到從ISearchResponse ID值(根據您的代碼上面的例子)通過查看Hits集合中的對象,而不是Documents集合。每個Hit都有Id屬性。

在原來的索引調用(假設你正在做的是獨立 - 不是通過_bulk端點),就可以得到新的索引文件關閉IIndexResponseId的屬性的ID。

+0

謝謝! +1代表。爲你 –

相關問題