1

My Problem is..

when I want to get last Document ID in Solr I get 99999999 and last Id = 246458031

I try this How to get last indexed record in Solr?

and only work if last ID <= 99999999

2.and when I use timestamp many record have the same date [timestamp": "2017-08-14T08:51:21.185Z]

So I need way to get Last Id from Solr

EDIT

I found Solution [q=*:*&start=0&rows=1&sort=timestamp+desc,id+desc] I Sorted by time & ID and it's working So Good

Osama Hashem
  • 90
  • 1
  • 12
  • Well, even if they DO have the same date, the precision internally in Solr is higher for a timestamped field than what you're showing. Is the last indexed record returned wrong? You also have the docid available, but I'm not sure if that's always growing (and that might be core specific and not usable across a collection); You don't have an ID field that's growing on your documents by yourself? – MatsLindh Aug 14 '17 at 09:43
  • if result have 10 record have the same time , and i sorted by timestamp i didn't get last ID – Osama Hashem Aug 14 '17 at 10:59
  • .. so if you have the IDs, why aren't you sorting by the ID? Are you indexing your ids as text, and not as actual integers? – MatsLindh Aug 14 '17 at 11:24
  • IDs integer ... I just need to get last ID , if table less than 100 Million it's so easy by this way[q=*:*&start=0&rows=1&sort=id+desc] in my case Last ID number is **246458031** if I do this Query with sorting Result will be : **99999999** And it's not true – Osama Hashem Aug 14 '17 at 12:14
  • I think Solr just Sorted first 100 million ... I no know why ?! And I need any way to get last ID if it's possible – Osama Hashem Aug 14 '17 at 12:15
  • I found Solution _q=*:*&start=0&rows=1&sort=timestamp+desc,id+desc_ I Sorted by time & ID and it's working So Good – Osama Hashem Aug 14 '17 at 12:58
  • Then your ids are not stored as integers, but as text/string (which would order 9xx in front of 2xxxx). The only reason why it works for your solution is that you don't have overlapping IDs inside the same timestamp - but when you go from 9xx to 1xxx, you'll get the wrong result for a second. – MatsLindh Aug 14 '17 at 13:19

2 Answers2

0

I found Solution

[q=:&start=0&rows=1&sort=timestamp+desc,id+desc] I Sorted by time & ID and it's working So Good

Osama Hashem
  • 90
  • 1
  • 12
  • I still don't think your ids are stored as integers, but as strings. If you switch them to being integers, the sort should work by just ordering by `id`. This solution would give the wrong number when the id rolls over to a new digit (i.e. 9 => 10, 99 => 100, etc.). That might not be a problem (especially when you're already up in the hundred million range), but be aware of the possible issue. – MatsLindh Nov 07 '17 at 08:10
0

You can sort by _version_ field in descending order. AFAIK, _version_ field is a epoch timestamp (of when the document was indexed into Solr) in milliseconds multiplied by 2^20.

Relevant code snipped from 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;
  }
}
genonymous
  • 1,598
  • 3
  • 18
  • 27