簡體   English   中英

ElasticSearch-如何從插入查詢中獲取自動生成的ID

[英]ElasticSearch - how to get the auto generated id from an insert query

在我的ElasticSearch數據庫上,我需要從我的插入查詢中獲取自動生成的ID(我正在使用.NET C#)。 怎么做? 我嘗試調試readRecords響應,但未找到此類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 

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

在原始索引調用中(假設您是單獨進行此操作-而不是通過_bulk端點進行此_bulk ),可以從IIndexResponseId屬性獲取新索引文檔的Id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM