0

我正在尝试在 elasticsearch curator 翻转操作中使用日期数学,但它似乎不支持别名作为日期数学,如 '<indexname-{now/d}>'

---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True.  If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
  1:
    action: rollover
    description: >-
      Rollover the index associated with alias 'indexname-{now/d}', index should be in the format of indexname-{now/d}-000001.
    options:
      disable_action: False
      name: '<indexname-{now/d}>'
      conditions:
        max_age: 1d
        max_docs: 1000000
        max_size: 50g
      extra_settings:
        index.number_of_shards: 3
        index.number_of_replicas: 1

它将名称 '<indexname-{now/d}>' 作为字符串/别名并给出错误

Failed to complete action: rollover. <class 'ValueError'>: Unable to perform index rollover with alias "<indexname-{now/d}>".

我建议在弹性搜索策展人中为翻转操作添加对日期数学的支持。

4

1 回答 1

0

看起来您正在尝试做的是翻转一个名为indexname-2021.10.28. 那是对的吗?我提到这一点是因为该name指令用于别名而不是索引名称。此外,使用此模式将查找具有今天date的别名{now/d},但翻转条件似乎正在查找早于 1 天(或 1M 文档或超过 50g)的内容。如果该别名超过 24 小时,则查找将失败,因为它正在查找可能尚未创建的内容。

我认为您更有可能寻找一个名称类似的别名index name指向看起来像indexname-YYYY.MM.dd. 如果原始索引和别名组合是使用日期数学创建的,您是否知道这种行为是自动的?

例如,如果我昨天创建了这个索引 + 别名组合(并且它经过 URL 编码以便在开发工具控制台中使用):

# PUT <my-index-{now/d}-000001>
PUT %3Cmy-index-%7Bnow%2Fd%7D-000001%3E
{
  "aliases": {
    "my-index": {
      "is_write_index": true
    }
  }
}

结果会说:

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "my-index-2021.10.27-000001"
}

如果我今天强制翻转:

POST my-index/_rollover
{
  "conditions": {
    "max_age": "1d"
  }
}

这是结果输出:

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "old_index" : "my-index-2021.10.27-000001",
  "new_index" : "my-index-2021.10.28-000002",
  "rolled_over" : true,
  "dry_run" : false,
  "conditions" : {
    "[max_age: 1d]" : true
  }
}

使用此行为,在索引名称中获取日期并仍使用默认翻转行为非常简单。

于 2021-10-28T16:18:17.340 回答