2015-06-18 46 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代表。为你 –

相关问题