如何使用Elasticsearch过渡API(别名已更新以指向最新创建的索引)?

时间:2020-05-06 18:47:42

标签: elasticsearch logstash

我有一个Logstash管道,该管道每天运行,并使用Module1索引签名将数据推送到Elasticsearch。因此,每天我都会创建一个新索引,例如:2020年5月5日的agent_index_2020_05_05和2020年5月6日的agent_index_2020_05_06。

对于此座席索引别名,使用它的映射进行更新,效果很好,但是我的要求是,座席别名应始终仅指向1个索引(即最新索引)。

映射

agent_index_%{+YYYY_MM_dd}

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

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

错误

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

是否有一种使用Elasticsearch Rollover API的方式仅允许在别名中更新最新创建的索引,这意味着在给定点,别名仅指向一个索引,即最新索引?

注意:使用Elasticsearh v6.2.4

更新

我的Logstash配置

{
  "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
}

更新

使用monitoring API来获取@Val建议的详细信息,但是每次运行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" } } 时,我都会得到不同的IN计数。请检查下面的屏幕截图。那么如何确定是否提取了全部事件?

enter image description here

1 个答案:

答案 0 :(得分:1)

在ES 6.2中,过渡API要求索引名称以序列号结尾,例如scan 0 count 10000 match a*。但是,如果不是这种情况,那么也可以使用其他索引名称,但是您需要在翻滚调用中使用specify it explicitly,如下所示:

-00001

因此,如果别名POST /agent/_rollover/agent_index_2020_05_13 { "conditions": { "max_age": "1d" } } 指向的索引早于一天,则翻转调用将创建一个名为agent的新索引。

注意:但是,由于ES 6.2.4是EOL,因此您应该将堆栈升级到至少6.6,然后在Logstash中免费获得ILM support,并且它将负责在ES中正确设置所有内容。