[英]Elasticsearch document ttl not working
我正在按照文档中给出的示例为Elasticsearch中的文档添加ttl: http : //www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/docs-index_.html#index-ttl
在Chrome上使用Sense工具,我尝试了以下操作,希望文档在5秒钟内消失:
PUT /twitter/tweets/2
{
"_ttl" : "5000",
"user" : "Romonov",
"TestField" : "TestData2"
}
PUT /twitters/tweetsy/1?ttl=5000
{
"user" : "Romonov",
"TestField" : "TestData1"
}
以上各项均无效,并且5秒钟后仍可见文档。 我还尝试在该索引上创建任何文档之前设置enable _ttl:
PUT /twig/twigsy/_mapping?pretty
{
"user" : {"_ttl": {"enabled": true}}
}
在哪里,我还没有将任何文档放在索引树枝上。 但这返回一个错误:
{
"error": "IndexMissingException[[twig] missing]",
"status": 404
}
我用curl(在Windows机器上安装了它)尝试了同样的方法,但是得到了同样的错误:
C:\WINDOWS\system32>curl -XPUT "http://localhost:9200/facebook/fb/_mapping?pretty" -d "{ "user" : {"_ttl": {"enabled": true}}"
{
"error" : "IndexMissingException[[facebook] missing]",
"status" : 404
}
想知道我缺少什么。
TTL文档对此进行了解释:
过期的文档将定期自动删除。 您可以动态设置indexs.ttl.interval以适合您的需求。 默认值为60秒。
因此,仅在下一个到期任务运行时,才不会在达到TTL时立即删除文档。 您可以降低该作业的运行速度,但是这样做会降低性能。
我可以通过做两件事来使其工作:
1.将以下行添加到elasticsearch.yml文件中:
indices.ttl.interval: 7d
2.使用以下几行在与elasticsearch.yml相同的位置创建一个default-mapping.json文档:
{
_default_ : {
"_ttl" : {
"enabled" : true, "default" : "7d"
}
}
}
完成这两项操作后创建的所有新群集均已将ttl启用为7天。 根据我的观察,到目前为止,它适用于在这些新集群上创建的所有索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.