Know indexing time for a document in Solr

2019-09-06 03:01发布

问题:

Is it possible to know the indexing time of a document in solr. Like there is a implicit field for "score" which automatically gets added to a document, is there a field that stores value of indexing time?

I need it to know the date when a document got indexed.

Thanks

回答1:

Solr does not automatically add a create date to documents. You could certainly index one with the document though, using Solr's DateField. In earlier versions or Solr ( < 4.2 ), there was a commented timestamp field in the example schema.xml, which looked like:

<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>

Also, I think it bears noting that there is no implicit "score" field. Scores are calculated at query time, rather than being tied to the document. Different queries will generate different scores for the same document. There are norms stored with the document that are factored into scores, but they aren't really fields.



回答2:

femtoRgon give you a correct solution but you must be carefull with partial document update. If you do not do partial document update you can stop reading now ;-)

If you partially update your document, SolR will merge the existing value with your partial document and the timestamp will not be updated. The solution is to not store the timestamp, then SolR will not be able to merge this value. The drawback is you cannot retrieve the timestamp with your search result.