自动删除文档在Apache Solr中不起作用

时间:2017-10-05 11:02:16

标签: apache solr lucene solr4

我正在使用Apache Solr 7并尝试自动删除文档。我按照Lucene的文档完成了以下步骤。

步骤1.在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" /> 

在managed-schema.xml中的第2步

<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" />

步骤3.我按名称sample1创建了一个核心,并添加了以下文档

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"}]' 
10秒后,文件仍在那里。我错过了任何一步,在这里还是我做错了什么?

1 个答案:

答案 0 :(得分:1)

我认为在索引编制中,您应该设置字段time_to_live_s而不是expire_at_dt,并设置值+10SECONDS或任何您想要的字段。

作为参考:

  

ttlFieldName - 此进程应在每个字段中查找的字段的名称   文档已处理,默认为 ttl 。如果指定了字段名称   存在于文档中,文档字段值将被解析为a   日期数学表达式相对于NOW,结果将被添加到   使用expirationFieldName的文档。用于禁用此功能。

如果您想直接设置到期日期 - 您应该设置正确的日期字符串,而不是日期数学表达式。

我有自动删除代码here

的完整工作示例
相关问题