简体   繁体   中英

auto delete of documents is not working in Apache Solr

I am using Apache Solr 7 and trying to automate deletion of documents. I've done following steps as per Lucene's documentation.

step 1. in solrschema.xml

<updateRequestProcessorChain default="true"> 
<processor class="solr.processor.DocExpirationUpdateProcessorFactory"> 
  <int name="autoDeletePeriodSeconds">30</int> 
  <str name="ttlFieldName">time_to_live_s</str> 
  <str name="expirationFieldName">expire_at_dt</str> 
</processor> 
<processor class="solr.LogUpdateProcessorFactory" /> 
<processor class="solr.RunUpdateProcessorFactory" /> 

step 2. in managed-schema.xml

<field name="id" type="string" indexed="true" stored="true" multiValued="false" />
<field name="time_to_live_s" type="string" stored="true" multiValued="false" />
<field name="expire_at_dt" type="date" stored="true" multiValued="false" />

step 3. I created a core by name sample1 and add the following document

curl -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/sample1/update?commit=true' -d '[{ "id":"sample_doc_1","expire_at_dt":"NOW+10SECONDS"}]' 

after 10 Seconds, the document is still there. Am i missing any of the step, here or am I doing something wrong ?

I think in the indexing you should set the field time_to_live_s not the expire_at_dt , and value +10SECONDS or whatever you want will be fine.

As a reference:

ttlFieldName - Name of a field this process should look for in each document processed, defaulting to ttl . If the specified field name exists in a document, the document field value will be parsed as a Date Math Expression relative to NOW and the result will be added to the document using the expirationFieldName. Use to disable this feature.

If you want to directly set the expiration date - you should set the proper date string, not the Date Math Expression.

I have full working example of the auto delete code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM