在 elasticsearch 5.6.0 中基于别名和模板翻转时遇到错误

Facing error while rollover based on alias and template in elasticsearch 5.6.0

我在翻转特定别名时遇到了一个奇怪的问题。 错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "index name [twitter] does not match pattern '^.*-\d+$'"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "index name [twitter] does not match pattern '^.*-\d+$'"
  },
  "status": 400
}

我有一个模板如下:

{
     "template": "twitter-*",
     "settings": {
       "number_of_shards": 3
     },
     "mappings" : {
           "user" : {
             "properties" : {
                "name" : { "type" : "text" },
                    "id" : { "type" : "text" }
              }
          }
      }
 }

和别名列表

 GET /_aliases
{
  "twitter": {
    "aliases": {}
  },
  ".kibana": {
    "aliases": {}
  },
  "twitter-2019.06.09-1": {
    "aliases": {
      "twitter-alias": {}
    }
  },
  "twitter123": {
    "aliases": {}
  }
}

我通过 takng 快照和恢复过程从 twitter 索引创建了 twitter-2019.06.09-1。

每当我尝试手动跟随翻转(我是由策展人设置的)时,我都会遇到上述错误。

#Running manual rollover
POST /twitter-alias/_rollover/
{
  "conditions": {
    "max_age":   "7d",
    "max_docs":  1
  }
}

twitter-2019.06.09-1 有以下3条记录:

GET twitter-2019.06.09-1/user/_search?size=0
{
  "took": 44,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 0,
    "hits": [ ]
  }
}

我曾尝试删除推特索引,因为它没有用,但由于翻转 api。

请帮忙。

更新:

阅读下文后post: https://discuss.elastic.co/t/rollover-failing/153676/5

我更新了模板和索引别名列表如下:

#Creating template for new index creation
PUT _template/template_1
{
  "template": "twitter-*",
  "settings": {
    "number_of_shards": 3
  },
"mappings" : {
        "user" : {
            "properties" : {
                "name" : { "type" : "text" },
                "id" : { "type" : "text" }
            }
        }
    },
    "aliases":
    {
    "search-all":{}
    }
}

和索引:

GET twitter-2019.06.09-1
{
  "twitter-2019.06.09-1": {
    "aliases": {
      "search-all": {},
      "twitter-alias": {}
    },
    "mappings": {
      "user": {
        "properties": {
          "id": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1559904447882",
        "number_of_shards": "1",
        "number_of_replicas": "1",
        "uuid": "DnUZcHiyQIi2ab8XVKKVuA",
        "version": {
          "created": "5060099"
        },
        "provided_name": "twitter"
      }
    }
  }
}

问题仍然存在。

我注意到了

"provided_name": "twitter"

正在检查索引信息。

是否与上述错误posted有关?它不应该是推特。这是一个错误吗?

我的重命名索引策略是:

#Taking snapshot
PUT /_snapshot/eaa-backup/twitter_snapshot
{
  "indices": "twitter",
  "ignore_unavailable": true,
  "include_global_state": false
}

并恢复:

#Now restore with new name
POST /_snapshot/eaa-backup/twitter_snapshot/_restore
{
 "indices": "twitter",
 "ignore_unavailable": "true",
 "include_global_state": false,
 "rename_pattern": "twitter",
 "rename_replacement": "twitter-2019.06.09-1"
 }

请帮忙找出上述错误的原因。此外,我在弹性讨论中 post 编辑了同样的问题,但似乎需要几天时间才能在那里找到帮助。所以,post 在这里。提前致谢。

我已经回答了这个问题here,但包括我提供的答案以供参考。

滚动索引通常必须以破折号和数字结尾(您必须通过滚动 API 调用来解决这个问题)。 Curator 正在检查与您的翻转别名相关联的索引(在粘贴的块中为 twitter),该别名不以破折号和数字结尾。

我不太确定你做错了什么。这是一个工作示例:

PUT twitter-2019.06.09-1
{
  "aliases": {
    "twitter-alias": {
      "is_write_index": true
    }
  }
}

PUT twitter-alias/_doc/1
{
  "doc1": "dummy_doc1"
}
PUT twitter-alias/_doc/2
{
  "doc2": "dummy_doc2"
}

结果:

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "old_index" : "twitter-2019.06.09-1",
  "new_index" : "twitter-2019.06.09-000002",
  "rolled_over" : true,
  "dry_run" : false,
  "conditions" : {
    "[max_docs: 1]" : true
  }
}

此外:

GET twitter-alias

产量:

{
  "twitter-2019.06.09-000002" : {
    "aliases" : {
      "twitter-alias" : {
        "is_write_index" : true
      }
    },
    "mappings" : {...},
    "settings" : {
      "index" : {
        "creation_date" : "1560216263049",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "kMd6jt_dSWKSCW4ertSuLg",
        "version" : {
          "created" : "7010099"
        },
        "provided_name" : "twitter-2019.06.09-000002"
      }
    }
  },
  "twitter-2019.06.09-1" : {
    "aliases" : {
      "twitter-alias" : {
        "is_write_index" : false
      }
    },
    "mappings" : {...},
    "settings" : {
      "index" : {
        "creation_date" : "1560216199250",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "zjIKove5SXqAXSEfseYpQg",
        "version" : {
          "created" : "7010099"
        },
        "provided_name" : "twitter-2019.06.09-1"
      }
    }
  }
}

除了@untergeek 的回复。以下是问题的原因:

实际上,我今天早上试了一下,在做完所有新鲜事后发现了与@untergeek 提到的相同。似乎在通过拍摄快照和恢复重命名索引时(参考:),

"provided_name": "twitter"

属性(问题中的描述)设置错误,这就是我遇到问题的原因。它应该设置为

twitter-2019.06.09-1

问题不在于索引名称,而在于上面的 属性。

我的方案包括重命名索引然后滚动。