Automatically expiring Solr documents
There are use cases that require expiration of documents after a certain amount of time—they should either be deleted or marked as inactive after a given time or period. For example, let's assume that we have a web application that works as a link shortening service. One can paste a long link and get the short version of it. However, we would like the links to be expired after one hour from their creation. Of course, we can develop a periodic job on our application-side and make this happen, but we can also use Solr for this. This recipe will show you how to achieve such functionality with Solr.
How to do it...
For the purpose of this recipe, let's assume that we want our documents to expire 5 minutes after they were sent to indexation.
- We will start with the structure of the index, which looks as follows (we add it to our
schema.xml
file):<field name="id" type="string" indexed="true" stored="true...