我正在寻找一种方法来设置TTL的文件在我的ElasticSearch索引理想的一个属性在我的Spring Boot 应用程序
我试着用curl来做,但我得到了这个错误。
curl --location --request PUT 'http://localhost:9200/order_index/_mapping/order_doc' \
--header 'Content-Type: application/json' \
--data-raw '{
"_ttl": {
"enabled": true,
"default": "24h"
}
}'
错误:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [_ttl : {default=24h, enabled=true}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [_ttl : {default=24h, enabled=true}]"
},
"status": 400
}
2条答案
按热度按时间w1e3prcc1#
在 当前 最 新 版本 的 Elasticsearch ( 7.15 ) _ttl is not yet supported 中 , 你 必须 创建 Index Lifecycle Management 策略 。
因此 , 您 必须 声明 策略 来 管理 datalifecyle , 并 在 Map 上 设置 此 策略 。
像 这样 的 例子 :信息 生命 周期 管理 :
中 的 每 一 个
Map :
格式
jljoyd4f2#
**首先,**创建一个策略来描述何时删除索引
PUT〈-您的策略名称
**接下来,**创建一个模板以选择使用此策略的索引类型。
在两天后删除
现在,当您创建一个新的索引示例时:test 001,它将在2天后自动删除。
**注意:**对于旧索引,它不会分配给新策略,因此除非您分配它,否则它不会被删除.
您可以使用此API将所有旧索引分配给策略
PUT http://localhost:9200/test */_settings〈--您的旧索引在这里,可以使用模式
然后在到期日期之后,所有旧索引都将被完全删除。