![](/img/trans.png)
[英]How to return auto generated id in insert query in postgres sql
[英]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
),可以從IIndexResponse
的Id
屬性獲取新索引文檔的Id
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.