1

Can we use Solr _ version _ field as a timestamp/version so that we can query the latest documents from a particular _ version _ /timestamp?

My requirement is to periodically (daily) retrieve new documents from my solr index. But there is no data/timestamp field to use as a filter to query latest documents.

Can I use _ version _ field for this in Solr ? (As it's an automatically indexed field for every document)

Dileepa Jayakody
  • 535
  • 1
  • 6
  • 19

2 Answers2

1

You can index additional field to keep the index date for the documents.

<field name="indexeddate" type="date" default="NOW" indexed="true" stored="true"/>

Even, you do not need to index this field, as this field comes with default value "NOW". So whenever you index the document, indexeddate field will also be indexed with the recent date. Then you can perform solr date range query on this field to retrieve latest documents.

For more on Solr dates format and range queries https://lucene.apache.org/solr/guide/6_6/working-with-dates.html

Sanjay Dutt
  • 2,192
  • 16
  • 16
0

//1day ago(millisecondsecondminute*hour etc...)

long _versionBegin_= (System.currentTimeMillis()-(1000*60*60*24)) << 20;

//long versionNow= System.currentTimeMillis() << 20;

//solr query params

String params="q=_version_:["+_versionBegin_+" TO *]&sort=_version_ asc";

//url encoded(space to +(or %20))

String params="q=_version_:["+_versionBegin_+"+TO+*]&sort=_version_+asc";
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 08 '22 at 15:09