如何使用 Elasticsearch rollover API 其中别名更新为指向最新创建的索引?

How to use Elasticsearch rollover API where alias is updated to point to the latest created index?

我有一个 Logstash 管道,它每天 运行 运行并使用 agent_index_%{+YYYY_MM_dd} 索引签名将数据推送到 Elasticsearch。因此,每天我都会创建一个新索引,例如:agent_index_2020_05_05 代表 2020 年 5 月 5 日,agent_index_2020_05_06 代表 2020 年 5 月 6 日。

因为这个代理索引别名是使用它的映射更新的,这工作正常,但我的要求是代理别名应该始终只指向 1 个索引,即最新索引。

映射

PUT /_template/agent_template
{
  "order": 0,
  "index_patterns": [
    "agent_index_*"
  ],
  "aliases": {
    "agent": {}
  }
}

我查看了 this,但看起来索引名称必须以递增数字结尾。

POST /agent/_rollover?dry_run
{
  "conditions": {
    "max_age": "1d"
  }
}

错误

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

有没有办法使用 elasticsearch rollover API 只允许在别名中更新最新创建的索引,这意味着在给定点别名仅指向一个索引,即最新索引?

注意:使用 ElasticSearh v6.2.4

更新

我的 Logstash 配置

input {
    jdbc {
        jdbc_driver_library => "ojdbc7.jar"
        jdbc_driver_class    => "Java::oracle.jdbc.OracleDriver"
        jdbc_connection_string => "jdbc:oracle:thin:@EDM:1521/aba"
        jdbc_user => "read"
        jdbc_password => "read"
        schedule => "50 6 * * *"
        statement_filepath =>"agent.sql"
       }
}
output {
    elasticsearch {
        hosts => "localhost:17002"
        index => "agent_index_%{+YYYY_MM_dd}"
        document_type => "agent"
    }
}

更新

按照@Val 的建议使用monitoring API 获取详细信息,但每次我运行 curl -XGET "localhost:15050/_node/stats/events?pretty" 都会得到不同的IN 计数。请检查下面的屏幕截图。那么如何确定是否提取了总事件?

在ES 6.2中,翻转API要求索引名以序号结尾,如-00001。但是,如果不是这种情况,那么也可以使用不同的索引名称,但您需要在翻转调用中 specify it explicitly,如下所示:

POST /agent/_rollover/agent_index_2020_05_13
{
  "conditions": {
    "max_age": "1d"
  }
}

因此,如果别名 agent 指向的索引早于一天,则滚动调用将创建一个名为 agent_index_2020_05_13 的新索引。

注意: 但是,由于 ES 6.2.4 EOL, you should upgrade your stack to at least 6.6, then you get ILM support 在 Logstash 中是免费的,它将负责在 ES 中正确设置所有内容。