Elasticsearch模块功能之-路由(routing)
2014-08-07 22:56
274 查看
索引分片分配能够控制索引分片在节点上怎么分布,那对于具体的文档能否控制具体节点的分布呢?答案是可以,根据路由公式shard = hash(routing) % number_of_primary_shards,Elasticsearch使用相同的routing参数来实现这个功能,但我们在创建索引时需如下进行配置:
如果我们想在建索引时将相关的文档存放到一个分片下就可以这样做:
这样将id为1和2的文档将会存在统一个分片上去。
既然索引文档的时候使用了路由,那么肯定得在查询的时候利用了,在查询的时候使用routing参数将使得查询更加高效,如下:
"mappings":{ "doc": { "_routing": { "required": true, "path":"_routing" }, "properties": { "title": { "type":"string" } } } }
如果我们想在建索引时将相关的文档存放到一个分片下就可以这样做:
curl- XPUT localhost: 9200 / documents / doc / 1 - d ' { "title": "Document No.1", "_routing":"A" }' curl- XPUT localhost: 9200 / documents / doc / 2 - d ' { "title": "Document No.1", "_routing":"A" }' curl- XPUT localhost: 9200 / documents / doc / 3 - d ' { "title": "Document No.1", "_routing":"B" }'
这样将id为1和2的文档将会存在统一个分片上去。
既然索引文档的时候使用了路由,那么肯定得在查询的时候利用了,在查询的时候使用routing参数将使得查询更加高效,如下:
curl-XGET 'localhost:9200/documents/_search?pretty&q=*:*&routing=A'
相关文章推荐
- Elasticsearch模块功能之-脚本语言(Scripting)
- Elasticsearch的路由(Routing)特性
- Elasticsearch的路由(Routing)特性
- Elasticsearch模块功能之-插件(Plugins)
- Elasticsearch模块功能之-索引模板(Index templates)
- Elasticsearch的路由(Routing)特性
- Elasticsearch模块功能之-快照和恢复(snapshot and restore)
- Elasticsearch模块功能之-映射(Mapper)
- Elasticsearch模块功能之-索引别名(Index aliases )
- ElasticSearch里面的路由功能介绍
- ElasticSearch里面的路由功能介绍
- RabbitMQ案例五之Routing路由功能
- Vue小模块之用户登录功能(一)工程创建和路由配置
- System.Web.Routing 路由功能详解(整理版)
- System.Web.Routing 路由功能详解(整理版)
- vue路由管理-保留滚动位置功能、按需加载模块名自定义
- Elasticsearch分片、副本与路由(shard replica routing)
- Elasticsearch的路由(Routing)特性
- Elasticsearch模块功能之-索引分片分配(Index shard allocation)
- Elasticsearch模块功能之-自动发现(Discovery)