如何在Solr中获取最后一个文档插入?

问题描述 投票:1回答:2

我的问题是......

当我想在Solr中获得最后一个文档ID时,我得到99999999,最后一个Id = 246458031

我试试这个How to get last indexed record in Solr?

并且只有在最后一个ID <= 99999999时才有效

2.当我使用时间戳时,许多记录都有相同的日期[timestamp“:”2017-08-14T08:51:21.185Z]

所以我需要从Solr获得Last Id

编辑

我找到了解决方案[q = *:*&start = 0&rows = 1&sort = timestamp + desc,id + desc] I按时间和ID排序,它工作得很好

solr solrj
2个回答
0
投票

我找到了解决方案

[q =:&start = 0&rows = 1&sort = timestamp + desc,id + desc] I按时间和ID排序,它的工作正常


0
投票

您可以按_version_字段降序排序。 AFAIK,_version_字段是一个纪元时间戳(当文档被索引到Solr时),以毫秒为单位乘以2^20

来自Solr codebase的相关代码片段:

public long getNewClock() {
  synchronized (clockSync) {
    long time = System.currentTimeMillis();
    long result = time << 20;
    if (result <= vclock) {
      result = vclock + 1;
    }
    vclock = result;
    return vclock;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.