Allocate
官网文档链接:Allocate | Elasticsearch Guide [7.12] | Elastic
Allocate允许的阶段:warm,cold;
更新索引设置以更改允许托管索引分片的节点并更改副本数量。
hot阶段不允许进行Allocate操作。索引的初始分配必须手动或通过Index templates | Elasticsearch Guide [7.12] | Elastic完成
您可以配置此操作以同时修改分配规则和副本数量、仅修改分配规则或仅修改副本数量。有关 Elasticsearch 如何使用副本进行扩展的更多信息,请看:Scalability and resilience: clusters, nodes, and shards | Elasticsearch Guide [7.12] | Elastic
查阅Index-level shard allocation filtering | Elasticsearch Guide [7.12] | Elastic,了解有关控制 Elasticsearch 分配特定索引分片的位置的更多信息。
选项(Options)
必须指定Number of replicas或至少一个include、exclude或require选项。空分配操作无效
有关使用自定义属性进行分片分配的更多信息,请参阅 Index-level shard allocation filtering | Elasticsearch Guide [7.12] | Elastic
- number_of_replicas:(可选,整型)指定给index 的副本数;
- include:(可选,对象(object))将index 分配给至少具有一个指定自定义属性的节点;
- exclude:(可选,对象(object))将index分配给不具有任何指定自定义属性的节点;
- require:(可选,对象(object))将索引分配给具有所有指定自定义属性的节点;
样例(Example)
修改副本数
以下策略中的分配操作将索引的副本数更改为 2。索引分配规则不变
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "number_of_replicas" : 2 } } } } } }
将索引分配给特定节点并更新副本设置(Assign index to a specific node and update replica settings)
以下策略中的分配操作将索引分配给 box_type 为 hot 或 Warm 的节点
要指定(designate)节点的 box_type,您可以在节点配置中设置自定义属性。例如,在elasticsearch.yml中设置node.attr.box_type: hot。有关更多信息,请参阅Index-level shard allocation filtering | Elasticsearch Guide [7.12] | Elastic
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "include" : { "box_type": "hot,warm" } } } } } } }
根据多个属性为节点分配索引(Assign index to nodes based on multiple attributes)
allocate 操作还可以根据多个节点属性为节点分配索引。以下操作根据 box_type 和Storage节点属性分配索引
PUT _ilm/policy/my_policy { "policy": { "phases": { "cold": { "actions": { "allocate" : { "require" : { "box_type": "cold", "storage": "high" } } } } } } }
将索引分配给特定节点并更新副本设置(Assign index to a specific node and update replica settings)
以下策略中的分配操作将索引更新为每个分片有一个副本,并分配给 box_type 为 Cold 的节点。
要指定节点的 box_type,您可以在节点配置中设置自定义属性。例如,在elasticsearch.yml中设置node.attr.box_type:cold。有关更多信息,请参阅Index-level shard allocation filtering | Elasticsearch Guide [7.12] | Elastic。
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "allocate" : { "number_of_replicas": 1, "require" : { "