Search code examples
solrsolrjsolrcloud

Solr auto delete using default value of ttl field


I am trying to use Solr auto-delete feature with solr-6. I have made the following changes in my managed-schema.xml and solrconfig.xml.

managed-schema

<!--expiration date field-->
<field name="eDate" type="date" multiValued="false" indexed="true" stored="true"/>
<field name="ttl" type="string" multiValued="false" indexed="true" stored="true" default="+90SECONDS"/>

solrconfig

<processor class="solr.processor.DocExpirationUpdateProcessorFactory">
    <int name="autoDeletePeriodSeconds">30</int>
    <str name="ttlFieldName">ttl</str>
    <str name="expirationFieldName">eDate</str>
</processor>

I am able to use auto delete feature as expected if I explicitly set the ttl field either in the incoming document or if I set the ttl request parameter in the update request. However, I want to use a default value for ttl as specified in the managed-schema if I do not explicitly set the ttl field. When I try this, ttl field is generated with the default value but the corresponding eDate field is not generated.

Is it possible to do what I am trying to do? If yes, then how can I do this? Please leave a comment if you need any further details.


Solution

  • I couldn't make it working via default param in field description, but I make it working via adding solr.DefaultValueUpdateProcessorFactory

    In my update chain I have this:

        <processor class="solr.DefaultValueUpdateProcessorFactory">
            <str name="fieldName">ttl</str>
            <str name="value">+15SECONDS</str>
        </processor>
        <processor class="solr.processor.DocExpirationUpdateProcessorFactory">
            <int name="autoDeletePeriodSeconds">5</int>
            <str name="ttlFieldName">ttl</str>
            <str name="expirationFieldName">eDate</str>
        </processor>
    

    I change values to have a quicker test :) Link to the working code