索引恢复优先级

编辑

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

  • 可选的 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
}