pengtaoli
pengtaoli

Reputation: 81

How to delete the documents a month ago

We are using Solr 1.4.

How to delete the documents a month ago?

Upvotes: 5

Views: 5785

Answers (2)

Paige Cook
Paige Cook

Reputation: 22555

We are doing something similar where we purge items from one of our indexes, using curl and taking advantage of the timestamp field in the Solr schema.

Here is the curl command that you would issue to delete items older than 30 days (using DateMathParser to calculate based on current day), using the timestamp field in the schema.

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

Of course you will need to change the url to match your solr instance and you may choose to use a different field.

Also here is the field definition for the timestamp field from the schema.xml that comes with the Solr distribution in the example folder.

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

Upvotes: 7

lindstromhenrik
lindstromhenrik

Reputation: 1143

You need to POST in order to do deletes but if you use the post.jar from the example folder in the installation it is simply:

java -Ddata=args -Dcommit=yes -jar post.jar "<delete><query>$DateField:[* TO $DateOneMonthAgo]</query></delete>"

where $DateField is the name of the field where the date is stored and $DateOneMonthAgo is the date one month from now (2011-11-09T11:48:00Z)

Upvotes: 5

Related Questions