Solr4.1 Cant delete documents older than 30 days

2019-06-09 05:52发布

问题:

I am running Solr4.1. I do have a version field but I do not understand how to delete by query with regards to time. I dont have any field in my schema that has a timestamp in it that I can see.

What I am trying to do is run a query that deletes all documents older than say 30 days.

I have tried everything I can find on the net.

curl http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>_version_:[* TO NOW-60DAYS] </query></delete>'

curl http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>timestamp:[* TO NOW-60DAYS] </query></delete>'

curl http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>createTime:[* TO NOW-60DAYS] </query></delete>'

other deletes work fine eg

curl http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>field:value</query></delete>'

回答1:

You can enable the timestamp field that is included in the schema.xml, just it is commented out. That field is auto-populated with the current datetime each time a document is inserted into the index. Look for the following in your schema.xml:

 <!-- Uncommenting the following will create a "timestamp" field using
      a default value of "NOW" to indicate when each document was indexed.
   -->
 <!--
 <field name="timestamp" type="date" indexed="true" stored="true" 
    default="NOW" multiValued="false"/>
 -->

You will need to re-index your documents for them to have this value set.



标签: solr