【问题标题】:How to set TTL for documents in Elasticsearch index如何为 Elasticsearch 索引中的文档设置 TTL
【发布时间】:2021-11-16 23:37:37
【问题描述】:

我正在寻找一种方法来为我的 Elasticsearch 索引中的文档设置 TTL,最好是通过我的 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
}

【问题讨论】:

标签: elasticsearch spring-data-elasticsearch


【解决方案1】:

在当前最新版本的 Elasticsearch (7.15) _ttl is not yet supported 中,您必须创建 Index Lifecycle Management 策略。

因此,您必须声明管理数据生命周期的策略并在映射上设置此策略。

例如这样: 工业光魔:

PUT _ilm/policy/my_policy {   "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_primary_shard_size": "25GB" 
          }
        }
      },
      "delete": {
        "min_age": "30d",
        "actions": {
          "delete": {} 
        }
      }
    }   } }

映射:

PUT test-index
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "index.lifecycle.name": "my_policy" 
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 2016-08-03
    • 2014-05-05
    相关资源
    最近更新 更多