Search code examples
solrsolrj

Is there a way to query Solr for a document with the most recent time field?


If my solr documents has a

<field name="timestamp" type="solr.TrieDateField" indexed="true" stored="true"  required="true" multiValued="false"/>

how can i query for the most recent document?

Only way I've discovered so far is to sort by descending date and limit rows to 1 but that has some limitations when i want something like get the most recent version of documents with id 1,2,3,4

something similar to this Get records with highest/smallest <whatever> per group


Solution

  • I seem to have gotten the results im looking for by using a solr group query

      group=true&group.field=groupId&group.sort=timestamp desc