单个节点上索引的分片总数超过限制
编辑单个节点上索引的分片总数超过限制
编辑Elasticsearch 尝试通过在集群中的节点之间分配数据(索引分片)来利用所有可用资源。
用户可能希望通过将 index.routing.allocation.total_shards_per_node 索引设置配置为自定义值(例如,对于高流量索引,值为 1
)来影响此数据分配。各种限制索引在一个节点上可以有多少分片的配置可能会导致分片未分配,因为集群没有足够的节点来满足索引配置。
要解决此问题,请按照以下步骤操作
为了分配分片,我们需要增加可以在一个节点上并置的分片数量。我们将通过检查 index.routing.allocation.total_shards_per_node
索引设置 的配置并增加具有未分配分片的索引的配置值来实现此目的。
使用 Kibana
- 登录到 Elastic Cloud 控制台。
-
在 Elasticsearch 服务 面板中,单击您的部署名称。
如果您的部署名称被禁用,则您的 Kibana 实例可能不健康,在这种情况下,请联系 Elastic 支持。如果您的部署不包含 Kibana,您只需 先启用它。
-
打开部署的侧边导航菜单(位于左上角的 Elastic 徽标下方),然后转到 开发工具 > 控制台。
-
检查具有未分配分片的索引的
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 } }