【问题标题】:auto delete of documents is not working in Apache Solr自动删除文档在 Apache Solr 中不起作用
【发布时间】:2017-10-05 11:02:15
【问题描述】:

我正在使用 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" /> 

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

第 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 秒后,文档仍然存在。我错过了任何一步,还是我做错了什么?

【问题讨论】:

  • 首先 - autoDeletePeriodSeconds 值告诉 Solr 它应该多久删除一次过期的文档,因此在这种情况下,文档最多可以存在 40 秒。 expire_at_dt 也应该只是 +10SECONDS(而不是 NOW+...)。您是否在 expire_at_dt 字段中获得任何值?
  • 先生,如果我只添加+10SECONDS,它会给出错误Invalid date string: +10SECONDS。另外,我得到2017-10-05T16:46:22.049Z forexpire_at_dt 字段@MatsLindh

标签: apache solr lucene solr4


【解决方案1】:

我认为在索引中你应该设置字段time_to_live_s 而不是expire_at_dt,值+10SECONDS 或者任何你想要的都可以。

作为参考:

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

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

我有自动删除代码here的完整工作示例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多