首页 > 解决方案 > Is there a way to set TTL on a document within AWS Elasticsearch utilizing python library?

问题描述

I can't find anyway to setup TTL on a document within AWS Elasticsearch utilizing python elasticsearch library.

I looked at the code of the library itself, and there are no argument for it, and I yet to see any answers on google.

标签: pythonamazon-web-serviceselasticsearch

解决方案


没有,如果你愿意,你可以使用索引管理策略,它将在索引级别操作,而不是在文档级别。您有一点回旋余地,因为您可以创建一个模式data-*并拥有多个索引,data-expiring-2020-..., data-keep-me.

您可以将模板应用于模式data-expiring-*并设置转换以在 20 天后删除索引。如果您每天滚动到一个新索引,那么一旦超过 20 天,您将在一天结束时删除最早的一天。

这种方法更可取,因为如果您要删除可能会消耗大量集群容量的单个文档,而不是删除整个分片。其他 NoSQL 数据库(例如 DynamoDB)以类似的方式运行,通常您可以做的是向您的docs例如添加另一个字段deletionDate并将其添加到您的查询中以过滤掉标记为删除但在您的索引中仍然存在的文档作为删除作业尚未清理它们。这也是 DynamoDB 中 TTL 的行为方式,数据不会在 TTL 过期的那一刻被删除,而是分批删除以提高性能。


推荐阅读