使用alias-routing-filter解决单索引多shard的性能问题

使用alias/routing/filter解决单索引多shard的性能问题:


使用alias-routing-filter解决单索引多shard的性能问题_第1张图片
Alias.png

1.单索引多别名
2.每个别名具有routing值
3.每个别名具有filter语句

PUT user
POST /_aliases
{
"actions" : [
{
"add" : {
"index" : "user",
"alias" : "user1" ,
"routing" : "user1",
"filter" : { "term" : { "user" : "user1" } }
}
},
{
"add" : {
"index" : "user",
"alias" : "user2" ,
"routing" : "user2",
"filter" : { "term" : { "user" : "user2" } }
}
},
{
"add" : {
"index" : "user",
"alias" : "user3",
"routing" : "user3",
"filter" : { "term" : { "user" : "user3" } }
}
}
]
}

每个别名有了routing值,在索引和搜索相应别名时,会自动使用别名对应的routing值,有了filter则在搜索时,自动使用相应的filter对搜索结果进行过滤。
详细设计思路参考:https://discuss.elastic.co/t/over-allocation-of-shards/6448/6
关于routing
一个文档被索引到的shard由下面公式决定
shard = hash(routing) % number_of_primary_shards
routing可以是默认字符串,默认值是文档的id(_id)

问题:
I dont understand exactly the difference to build 1 shard per index and
this method to build 1 index + routing.
I understood that it's better for the system ressource but not exactly why ?
因为:
More of one user can use a same shard.
参考:
别名使用:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
routing:https://www.elastic.co/guide/en/elasticsearch/guide/current/routing-value.html
必须使用routing值:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html

你可能感兴趣的:(使用alias-routing-filter解决单索引多shard的性能问题)