0%

elasticsearch分片过滤

分片过滤

  • 第一步

在节点elasticsearch.yml配置中可以为节点增加自定义属性,如

# small,big,...
node.attr.size: medium

或者在启动时增加自定义属性

./bin/elasticsearch -Enode.attr.size=medium

节点自带属性

属性 说明
_name Match nodes by node name
_host_ip Match nodes by host IP address (IP associated with hostname)
_publish_ip Match nodes by publish IP address
_ip Match either _host_ip or _publish_ip
_host Match nodes by hostname
_id Match nodes by node id
_tier Match nodes by the node’s data tier role.
  • 第二步

创建或修改索引的分片过滤条件,支持require,exclude,include

PUT test/_settings
# 例1
{
  "index.routing.allocation.include.size": "big,medium"
}
# 例2
{
  "index.routing.allocation.require.size": "big",
  "index.routing.allocation.require.rack": "rack1"
}
# 例3
{
  "index.routing.allocation.include._ip": "192.168.2.*"
}