我如何知道创建索引的 Elasticsearch 版本?

问题描述 投票:0回答:3

有什么方法可以知道特定索引是在哪个 Elasticsearch 版本中创建的?

当您想要升级集群并且可能需要在升级集群之前将较旧的索引重新索引到较新版本以避免不兼容问题时,这主要有用。

例如,如果我们要升级到7.5版本,如果我们有在5.x或更早版本中创建的索引,则需要在升级到7.5.0之前重新索引或删除它们。如果存在不兼容的索引,Elasticsearch 节点将无法启动。 5.x 或更早版本索引的快照无法恢复到 7.x 集群,即使它们是由 6.x 集群创建的 (https://www.elastic.co/guide/en/elasticsearch/reference/current/ reindex-upgrade.html).

elasticsearch indexing lucene upgrade reindex
3个回答
7
投票

我们可以通过两个简单的调用来了解这一点:
-

GET my_index?human

-
GET my_index/_settings?human

在这两次通话中,您都会在响应中找到类似以下内容:

"version" : {
    "created_string" : "7.4.2",
    "created" : "7040299"
}

created
字段表示发布版本。仅当您包含
created_string
标志以获得更清晰的视图时,才会出现
?human
字段。


1
投票

我编写了这个 bash 脚本来获取每个索引的版本:

#!/bin/bash

INDICES=$(curl --silent "localhost:9200/_cat/indices?h=index")

for INDEX in $INDICES; do

 if [[ "$INDEX" == *geoip* ]]; then
  continue
 fi

 VERSION=$(curl --silent "localhost:9200/$INDEX/_settings?pretty" | grep "created" | cut -d'"' -f4)
 echo "Index: '$INDEX', version: '$VERSION'"

done

希望这对某人有帮助。这个脚本帮助我在Elasticsearch从7到8的升级过程中搜索旧的索引版本。


0
投票

您可以通过一次 api 调用获取所有索引版本:

curl -s http://localhost:9200/_all/_settings?pretty

© www.soinside.com 2019 - 2024. All rights reserved.