How to delete documents a month ago

We use Solr 1.4.

How to delete documents a month ago?

+4
source share
2 answers

We do something similar when we clear elements from one of our indexes using curl and use the timestamp field in the Solr schema.

Here is the curl command that you want to remove in order to remove items older than 30 days (using DateMathParser to calculate based on the 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 can use a different field.

It also provides a field definition of the timestamp field from the schema.xml file that comes with the Solr distribution in the sample folder.

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

You need to send POST for removal, but if you use post.jar from the examples folder in the installation, simply:

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

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

+5
source

Source: https://habr.com/ru/post/1385480/


All Articles