单节点上索引的分片总数超出限制
编辑单节点上索引的分片总数超出限制
编辑Elasticsearch 尝试通过在集群中的节点之间分配数据(索引分片)来利用所有可用资源。
用户可能希望通过将 index.routing.allocation.total_shards_per_node 索引设置配置为自定义值(例如,对于高流量索引,配置为 1
)来影响此数据分配。限制一个索引可以在一个节点上拥有的分片数量的各种配置可能会导致分片未分配,因为集群没有足够的节点来满足索引配置。
为了解决这个问题,请按照以下步骤操作
为了分配分片,我们需要增加可以在节点上共存的分片数量。我们将通过检查 index.routing.allocation.total_shards_per_node
索引设置 的配置,并增加未分配分片的索引的配置值来实现此目的。
使用 Kibana
- 登录到 Elastic Cloud 控制台。
-
在 Elasticsearch 服务 面板上,单击您的部署名称。
如果您的部署名称被禁用,则您的 Kibana 实例可能不正常,在这种情况下,请联系 Elastic 支持。如果您的部署不包括 Kibana,您只需先启用它。
-
打开部署的侧面导航菜单(位于左上角的 Elastic 徽标下),然后转到 Dev Tools > Console。
-
检查具有未分配分片的索引的
index.routing.allocation.total_shards_per_node
索引设置resp = client.indices.get_settings( index="my-index-000001", name="index.routing.allocation.total_shards_per_node", flat_settings=True, ) print(resp)
response = client.indices.get_settings( index: 'my-index-000001', name: 'index.routing.allocation.total_shards_per_node', flat_settings: true ) puts response
const response = await client.indices.getSettings({ index: "my-index-000001", name: "index.routing.allocation.total_shards_per_node", flat_settings: "true", }); console.log(response);
GET /my-index-000001/_settings/index.routing.allocation.total_shards_per_node?flat_settings
响应将如下所示
-
增加 可以在一个节点上分配的总分片数的值,使其更大
resp = client.indices.put_settings( index="my-index-000001", settings={ "index": { "routing.allocation.total_shards_per_node": "2" } }, ) print(resp)
response = client.indices.put_settings( index: 'my-index-000001', body: { index: { 'routing.allocation.total_shards_per_node' => '2' } } ) puts response
const response = await client.indices.putSettings({ index: "my-index-000001", settings: { index: { "routing.allocation.total_shards_per_node": "2", }, }, }); console.log(response);
为了分配分片,您可以向 Elasticsearch 集群添加更多节点,并将索引的目标层 节点角色 分配给新节点。
要检查索引的目标分配层,请使用 获取索引设置 API 来检索 index.routing.allocation.include._tier_preference
设置的配置值
resp = client.indices.get_settings( index="my-index-000001", name="index.routing.allocation.include._tier_preference", flat_settings=True, ) print(resp)
response = client.indices.get_settings( index: 'my-index-000001', name: 'index.routing.allocation.include._tier_preference', flat_settings: true ) puts response
const response = await client.indices.getSettings({ index: "my-index-000001", name: "index.routing.allocation.include._tier_preference", flat_settings: "true", }); console.log(response);
GET /my-index-000001/_settings/index.routing.allocation.include._tier_preference?flat_settings
响应将如下所示
{ "my-index-000001": { "settings": { "index.routing.allocation.include._tier_preference": "data_warm,data_hot" } } }
表示允许将此索引分配到的数据层节点角色的逗号分隔列表,列表中第一个是优先级较高的节点角色,即索引的目标层。例如,在此示例中,层首选项为 |
或者,如果不想向 Elasticsearch 集群添加更多节点,则检查 index.routing.allocation.total_shards_per_node
索引设置 的配置并增加配置值将允许在同一节点上分配更多分片。
-
检查具有未分配分片的索引的
index.routing.allocation.total_shards_per_node
索引设置resp = client.indices.get_settings( index="my-index-000001", name="index.routing.allocation.total_shards_per_node", flat_settings=True, ) print(resp)
response = client.indices.get_settings( index: 'my-index-000001', name: 'index.routing.allocation.total_shards_per_node', flat_settings: true ) puts response
const response = await client.indices.getSettings({ index: "my-index-000001", name: "index.routing.allocation.total_shards_per_node", flat_settings: "true", }); console.log(response);
GET /my-index-000001/_settings/index.routing.allocation.total_shards_per_node?flat_settings
响应将如下所示
-
增加 可以在一个节点上分配的总分片数,或者将该值重置为无界限 (
-1
)resp = client.indices.put_settings( index="my-index-000001", settings={ "index": { "routing.allocation.total_shards_per_node": -1 } }, ) print(resp)
response = client.indices.put_settings( index: 'my-index-000001', body: { index: { 'routing.allocation.total_shards_per_node' => -1 } } ) puts response
const response = await client.indices.putSettings({ index: "my-index-000001", settings: { index: { "routing.allocation.total_shards_per_node": -1, }, }, }); console.log(response);
PUT /my-index-000001/_settings { "index" : { "routing.allocation.total_shards_per_node" : -1 } }