多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 分片分配过滤 原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/index-modules-allocation.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/index-modules-allocation.html) 译文链接 : [分片分配过滤](/pages/viewpage.action?pageId=9405600) 贡献者 : @苏涛,[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) ### 分片分配过滤 分片分配过滤允许您指定哪些节点托管特定索引的分片。 注意 以下解释的每个索引分片分配过滤器与[Cluster Level Shard Allocation](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/shards-allocation.html)中介绍的群集范围分配过滤器同时生效。 可以在启动时为每个节点分配任意的**metadata** (元数据)属性。例如,节点可以按如下方式标记一个`rack` 属性和一个size属性: ``` bin/elasticsearch -Enode.attr.rack=rack1 -Enode.attr.size=big #1 ``` | 1 | 这些属性设置也可以在**elasticsearch.yml**配置文件中指定 | 这些**metadata(**元数据)属性可以与**index.routing.allocation*** 设置一起使用,以将索引分配给特定的节点组。例如,我们可以按如下所示将索引test移动到被标记为big或者`medium的`节点上: ``` PUT test/_settings { "index.routing.allocation.include.size": "big,medium" } ``` 或者,我们可以使用排除规则将索引test从标记为small的节点中移出: ``` PUT test/_settings { "index.routing.allocation.exclude.size": "small" } ``` 可以指定多个规则,在这种情况下必须满足所有条件。例如,我们可以将索引test移到rack1中的big节点上,具体如下: ``` PUT test/_settings { "index.routing.allocation.include.size": "big", "index.routing.allocation.include.rack": "rack1" } ``` 注意 如果某些条件不能满足,则分片将不会被移动。 以下设置是动态的,允许活动索引从一组节点移动到另一组节点: **index.routing.allocation.include.{attribute}**     分配索引到一个节点,节点的{attribute}至少满足一个逗号分隔的值。 **index.routing.allocation.require.{attribute}**     分配索引到一个节点,节点的{attribute}满足所有逗号分隔的值。 **index.routing.allocation.exclude.{attribute}**     分配索引到一个节点,节点的{attribute}不满足任何逗号分隔的值。 还支持这些特殊的属性: _name                 通过节点名匹配节点 _host_ip               通过主机IP地址(与主机名关联的IP)匹配节点 _publish_ip           通过**publish**(发布)IP地址匹配节点 _ip                        通过_host_ip或_publish_ip进行匹配 _host                    通过主机名匹配节点 可以使用通配符指定所有属性值,例如: ``` PUT test/_settings { "index.routing.allocation.include._ip": "192.168.2.*" } ```