索引恢复优先级

编辑

未分配的分片会尽可能按优先级顺序恢复。索引按以下优先级顺序排序:

  • 可选的 index.priority 设置(值越高优先级越高)
  • 索引创建日期(日期越新优先级越高)
  • 索引名称(按字母顺序,后字母比前字母优先级高)

这意味着,默认情况下,较新的索引将比旧的索引先恢复。

使用每个索引可动态更新的 index.priority 设置来自定义索引的优先级顺序。例如:

resp = client.indices.create(
    index="index_1",
)
print(resp)

resp1 = client.indices.create(
    index="index_2",
)
print(resp1)

resp2 = client.indices.create(
    index="index_3",
    settings={
        "index.priority": 10
    },
)
print(resp2)

resp3 = client.indices.create(
    index="index_4",
    settings={
        "index.priority": 5
    },
)
print(resp3)
response = client.indices.create(
  index: 'index_1'
)
puts response

response = client.indices.create(
  index: 'index_2'
)
puts response

response = client.indices.create(
  index: 'index_3',
  body: {
    settings: {
      'index.priority' => 10
    }
  }
)
puts response

response = client.indices.create(
  index: 'index_4',
  body: {
    settings: {
      'index.priority' => 5
    }
  }
)
puts response
const response = await client.indices.create({
  index: "index_1",
});
console.log(response);

const response1 = await client.indices.create({
  index: "index_2",
});
console.log(response1);

const response2 = await client.indices.create({
  index: "index_3",
  settings: {
    "index.priority": 10,
  },
});
console.log(response2);

const response3 = await client.indices.create({
  index: "index_4",
  settings: {
    "index.priority": 5,
  },
});
console.log(response3);
PUT index_1

PUT index_2

PUT index_3
{
  "settings": {
    "index.priority": 10
  }
}

PUT index_4
{
  "settings": {
    "index.priority": 5
  }
}

在上面的例子中

  • index_3 将首先恢复,因为它具有最高的 index.priority
  • index_4 将紧随其后恢复,因为它具有次高的优先级。
  • index_2 将接下来恢复,因为它创建时间较晚。
  • index_1 将最后恢复。

此设置接受整数值,并且可以使用更新索引设置 API在活动索引上进行更新

resp = client.indices.put_settings(
    index="index_4",
    settings={
        "index.priority": 1
    },
)
print(resp)
response = client.indices.put_settings(
  index: 'index_4',
  body: {
    'index.priority' => 1
  }
)
puts response
const response = await client.indices.putSettings({
  index: "index_4",
  settings: {
    "index.priority": 1,
  },
});
console.log(response);
PUT index_4/_settings
{
  "index.priority": 1
}