On my ElasticSearch database I need to get the autogenerated id from my insert query (I'm using .NET C#). How to do it? I tried debugging the readRecords response but I didn't find such id.
Basically I need the equivalent of the MySQL LAST_INSERT_ID() command.
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 theHitscollection, rather than theDocumentscollection. EachHithas anIdproperty.In the original indexing call (assuming you're doing that individually -- not via the
_bulkendpoint), you can get the id of the newly indexed document off theIIndexResponse'sIdproperty.