ElasticSearch集群环境下新增文档如何确认该文档被分配到哪个分片中?
路由算法:
?先这肯定不会是随机的,否则将来要获取?档的时候我们就不知道从何处寻找了。实际上,这个过程是根据下?这个公式决定的:
shard = hash(routing) % number_of_primary_shards
routing 是?个可变值,默认是?档的 _id ,也可以设置成?个?定义的值。 routing通过 hash 函数?成?个数字,然后这个数字再除以 number_of_primary_shards (主分
PUT /nba/_doc/1
{
"name": "哈登",
"team_name": "?箭",
"position": "得分后卫",
"play_year": "10",
"jerse_no": "13"
}
查看?档在哪个分?上
GET /nba/_search_shards?routing=1
{
"nodes" : {
"V1JO7QXLSX-yeVI82WkgtA" : {
"name" : "node-1",
"ephemeral_id" : "_d96PgOSTnKo6nrJVqIYpw",
"transport_address" : "192.168.1.101:9300",
"attributes" : {
"ml.machine_memory" : "8589934592",
"xpack.installed" : "true",
"ml.max_open_jobs" : "20"
}
},
"z65Hwe_RR_efA4yj3n8sHQ" : {
"name" : "node-3",
"ephemeral_id" : "MOE_Ne7ZRyaKRHFSWJZWpA",
"transport_address" : "192.168.1.101:9500",
"attributes" : {
"ml.machine_memory" : "8589934592",
"ml.max_open_jobs" : "20",
"xpack.installed" : "true"
}
}
},
"indices" : {
"nba" : { }
},
"shards" : [
[
{
"state" : "STARTED",
"primary" : true,
"node" : "V1JO7QXLSX-yeVI82WkgtA",
"relocating_node" : null,
"shard" : 2,
"index" : "nba",
"allocation_id" : {
"id" : "leX_k6McShyMoM1eNQJXOA"
}
},
{
"state" : "STARTED",
"primary" : false,
"node" : "z65Hwe_RR_efA4yj3n8sHQ",
"relocating_node" : null,
"shard" : 2,
"index" : "nba",
"allocation_id" : {
"id" : "6sUSANMuSGKLgcIpBa4yYg"
}
}
]
]
}
原文:https://www.cnblogs.com/july-sunny/p/14328963.html