分配
编辑分配
编辑允许的阶段:warm,cold。
更新索引设置,以更改允许托管索引分片的节点以及更改副本数量。
分配操作在 hot 阶段不允许。索引的初始分配必须手动完成或通过索引模板完成。
您可以配置此操作来修改分配规则和副本数量,仅修改分配规则,或仅修改副本数量。有关 Elasticsearch 如何使用副本进行扩展的更多信息,请参阅为生产做好准备。有关控制 Elasticsearch 在何处分配特定索引的分片的更多信息,请参阅索引级别的分片分配过滤。
选项
编辑您必须指定副本数量或至少一个 include
、exclude
或 require
选项。一个空的分配操作是无效的。
有关使用自定义属性进行分片分配的更多信息,请参阅索引级别的分片分配过滤。
-
number_of_replicas
- (可选,整数)要分配给索引的副本数量。
-
total_shards_per_node
- (可选,整数)单个 Elasticsearch 节点上索引的最大分片数。值
-1
被解释为无限制。请参阅每个节点的总分片数。 -
include
- (可选,对象)将索引分配给至少具有一个指定自定义属性的节点。
-
exclude
- (可选,对象)将索引分配给不具有任何指定自定义属性的节点。
-
require
- (可选,对象)将索引分配给具有所有指定自定义属性的节点。
示例
编辑以下策略中的分配操作将索引的副本数量更改为 2
。任何单个节点上最多放置 200 个索引分片。否则,索引分配规则不会更改。
resp = client.ilm.put_lifecycle( name="my_policy", policy={ "phases": { "warm": { "actions": { "allocate": { "number_of_replicas": 2, "total_shards_per_node": 200 } } } } }, ) print(resp)
response = client.ilm.put_lifecycle( policy: 'my_policy', body: { policy: { phases: { warm: { actions: { allocate: { number_of_replicas: 2, total_shards_per_node: 200 } } } } } } ) puts response
const response = await client.ilm.putLifecycle({ name: "my_policy", policy: { phases: { warm: { actions: { allocate: { number_of_replicas: 2, total_shards_per_node: 200, }, }, }, }, }, }); console.log(response);
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "number_of_replicas" : 2, "total_shards_per_node" : 200 } } } } } }
使用自定义属性将索引分配给节点
编辑以下策略中的分配操作将索引分配给 box_type
为 *hot* 或 *warm* 的节点。
要指定节点的 box_type
,您需要在节点配置中设置自定义属性。例如,在 elasticsearch.yml
中设置 node.attr.box_type: hot
。有关更多信息,请参阅启用索引级别的分片分配过滤。
resp = client.ilm.put_lifecycle( name="my_policy", policy={ "phases": { "warm": { "actions": { "allocate": { "include": { "box_type": "hot,warm" } } } } } }, ) print(resp)
response = client.ilm.put_lifecycle( policy: 'my_policy', body: { policy: { phases: { warm: { actions: { allocate: { include: { box_type: 'hot,warm' } } } } } } } ) puts response
const response = await client.ilm.putLifecycle({ name: "my_policy", policy: { phases: { warm: { actions: { allocate: { include: { box_type: "hot,warm", }, }, }, }, }, }, }); console.log(response);
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "include" : { "box_type": "hot,warm" } } } } } } }
根据多个属性将索引分配给节点
编辑分配操作还可以根据多个节点属性将索引分配给节点。以下操作根据 box_type
和 storage
节点属性分配索引。
resp = client.ilm.put_lifecycle( name="my_policy", policy={ "phases": { "cold": { "actions": { "allocate": { "require": { "box_type": "cold", "storage": "high" } } } } } }, ) print(resp)
response = client.ilm.put_lifecycle( policy: 'my_policy', body: { policy: { phases: { cold: { actions: { allocate: { require: { box_type: 'cold', storage: 'high' } } } } } } } ) puts response
const response = await client.ilm.putLifecycle({ name: "my_policy", policy: { phases: { cold: { actions: { allocate: { require: { box_type: "cold", storage: "high", }, }, }, }, }, }, }); console.log(response);
PUT _ilm/policy/my_policy { "policy": { "phases": { "cold": { "actions": { "allocate" : { "require" : { "box_type": "cold", "storage": "high" } } } } } } }
将索引分配给特定节点并更新副本设置
编辑以下策略中的分配操作将索引更新为每个分片有一个副本,并将其分配给 box_type
为 *cold* 的节点。
要指定节点的 box_type
,您需要在节点配置中设置自定义属性。例如,在 elasticsearch.yml
中设置 node.attr.box_type: cold
。有关更多信息,请参阅启用索引级别的分片分配过滤。
resp = client.ilm.put_lifecycle( name="my_policy", policy={ "phases": { "warm": { "actions": { "allocate": { "number_of_replicas": 1, "require": { "box_type": "cold" } } } } } }, ) print(resp)
response = client.ilm.put_lifecycle( policy: 'my_policy', body: { policy: { phases: { warm: { actions: { allocate: { number_of_replicas: 1, require: { box_type: 'cold' } } } } } } } ) puts response
const response = await client.ilm.putLifecycle({ name: "my_policy", policy: { phases: { warm: { actions: { allocate: { number_of_replicas: 1, require: { box_type: "cold", }, }, }, }, }, }, }); console.log(response);
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "number_of_replicas": 1, "require" : { "box_type": "cold" } } } } } } }