[英]ElasticSearch - how to get the auto generated id from an insert query
On my ElasticSearch database I need to get the autogenerated id from my insert query (I'm using .NET C#). 在我的ElasticSearch数据库上,我需要从我的插入查询中获取自动生成的ID(我正在使用.NET C#)。 How to do it? 怎么做? I tried debugging the readRecords response but I didn't find such id. 我尝试调试readRecords响应,但未找到此类ID。
Basically I need the equivalent of the MySQL LAST_INSERT_ID()
command. 基本上,我需要等效于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
You can find the id values from the ISearchResponse
(based on your code example above) by looking at the objects in the Hits
collection, rather than the Documents
collection. 您可以通过查看Hits
集合中的对象而不是Documents
集合,从ISearchResponse
(基于上面的代码示例)中找到id值。 Each Hit
has an Id
property. 每个Hit
都有一个Id
属性。
In the original indexing call (assuming you're doing that individually -- not via the _bulk
endpoint), you can get the id of the newly indexed document off the IIndexResponse
's Id
property. 在原始索引调用中(假设您是单独进行此操作-而不是通过_bulk
端点进行此_bulk
),可以从IIndexResponse
的Id
属性获取新索引文档的Id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.