# Cluster Reroute
原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cluster-reroute.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cluster-reroute.html)
译文链接 : [http://www.apache.wiki/display/Elasticsearch/Cluster+Reroute](http://www.apache.wiki/display/Elasticsearch/Cluster+Reroute)
贡献者 : [那伊抹微笑](/display/~wangyangting)
**reroute** 命令可以明确的执行包括指定命令的集群重新路由分配命令。例如,一个分片可以从一个节点明确的移动到另一个节点,分配可以被取消,或者未分配的分片可能被明确的分配到一个指定的节点。
下面是一个见简单的重新路由 **API** 调用的例子 :
```
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands" : [ {
"move" :
{
"index" : "test", "shard" : 0,
"from_node" : "node1", "to_node" : "node2"
}
},
{
"allocate_replica" : {
"index" : "test", "shard" : 1, "node" : "node3"
}
}
]
}'
```
要记住的一个重要方面是, 在分配时,集群将针对 **re-balancing**(重新平衡)它的状态到一个相等的状态。例如,如果分配包括从 **node1** 移动分片到 **node2**,在一个相等的状态中,其它的分片将会从 **node2** 移动到 **node1** 以达到平衡。
即可可以设置禁用分配,这意味着只有在明确的指定分配情况下才被执行。很显然,仅仅一次所有的命令被请求时,该集群将重新平衡它的状态。
另一种选择是在 **dry_run**(作为一个 **URI** 标记,或者在请求体中)中运行命令。这将导致命令应用到当前的集群状态,并且在命令别被执行后返回集群结果。
如果指定了 **explain** 参数,会返回命令可以或者不能被执行的详细的说明。
支持的命令是 :
| 命令 | 描述 |
| --- | --- |
| move | Move a started shard from one node to another node. Accepts `index` and `shard` for index name and shard number, `from_node` for the node to move the shard `from`, and `to_node` for the node to move the shard to. |
| cancel | Cancel allocation of a shard (or recovery). Accepts `index` and `shard` for index name and shard number, and `node` for the node to cancel the shard allocation on. It also accepts `allow_primary` flag to explicitly specify that it is allowed to cancel allocation for a primary shard. This can be used to force resynchronization of existing replicas from the primary shard by cancelling them and allowing them to be reinitialized through the standard reallocation process. |
| allocate_replica | Allocate an unassigned replica shard to a node. Accepts the `index` and `shard` for index name and shard number, and `node` to allocate the shard to. Takes [allocation deciders](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-cluster.html "Cluster") into account. |
两个更多的命令可用,允许分配主分片到节点。这些命令需要谨慎使用,因为主分片的分配通常有 **Elasticsearch** 自动处理。为什么主分片不能被自动分配的原因如下 :
* 一个新的索引被创建,但是没有满足分配策略者的节点。
* 一个最新的分片数据的副本,不能在集群中当前数据节点上找到。为了防止数据丢失,系统不会自动的促使一个稳定的分片复制为主分片。
在手动覆盖时,两个命令强制分配主分片可供选择 :
| 命令 | 描述 |
| --- | --- |
| allocate_stale_primary | Allocate a primary shard to a node that holds a stale copy. Accepts the `index` and `shard` for index name and shard number, and `node` to allocate the shard to. Using this command may lead to data loss for the provided shard id. If a node which has the good copy of the data rejoins the cluster later on, that data will be overwritten with the data of the stale copy that was forcefully allocated with this command. To ensure that these implications are well-understood, this command requires the special field `accept_data_loss` to be explicitly set to `true` for it to work. |
| allocate_empty_primary | Allocate an empty primary shard to a node. Accepts the `index` and `shard` for index name and shard number, and `node` to allocate the shard to. Using this command leads to a complete loss of all data that was indexed into this shard, if it was previously started. If a node which has a copy of the data rejoins the cluster later on, that data will be deleted! To ensure that these implications are well-understood, this command requires the special field `accept_data_loss` to be explicitly set to `true` for it to work. |
## Retry failed shards(重试故障的分片)
集群尝试分配一个分片的最大次数为 **index.allocation.max_retries**(默认为 **5**),在放弃和离开未分配的分片之前。该场景会造成结构上的问题,例如有一个分析器,它引用了一个在所有节点上不存在的 **stopwords** 文件。
在该问题被修复后,可以通过手动重复与 **?retry_failed** 一起调用 [`_reroute`](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cluster-reroute.html "Cluster Reroute") API,它将为那些节点单独的重试。
- Getting Started(入门指南)
- Basic Concepts(基础概念)
- Installation(安装)
- Exploring Your Cluster(探索集群)
- Cluster Health(集群健康)
- List All Indices(列出所有索引)
- Create an Index(创建索引)
- Index and Query a Document(索引和查询文档)
- Delete an Index(删除索引)
- Modifying Your Data(修改数据)
- Updating Documents(更新文档)
- Deleting Documents(删除文档)
- Batch Processing(批处理)
- Exploring Your Data(探索数据)
- The Search API(搜索 API)
- Introducing the Query Language(介绍查询语言)
- Executing Searches(执行查询)
- Executing Filters(执行过滤)
- Executing Aggregations(执行聚合)
- Conclusion(总结)
- Setup Elasticsearch(设置)
- Installing Elasticsearch(安装)
- zip 或 tar.gz 安装
- Debian软件包安装Elasticsearch
- 用RPM安装Elasticsearch
- Windows 环境下安装ES
- Docker 方式安装
- 配置Elasticsearch
- 重要Elasticsearch配置
- 安全配置
- 启动前检查
- 堆大小检查
- 文件描述符检查
- 内存锁定检查
- 最大线程数检查
- 最大虚拟内存检查
- 最大map数检查
- JVM Client模式检查
- 串行收集使用检查
- 系统调用过滤检查
- OnError与OnOutOfMemoryError检查
- G1GC检查
- 重要的系统配置
- 系统设置
- 在jvm.options中设置JVM堆大小
- 禁用swapping
- 文件描述符
- 虚拟内存
- 线程数
- 升级Elasticsearch
- Elasticsearch停机
- 重大改变
- 在5.3 重大改变
- 在5.2 重大改变
- Shadow Replicas已被弃用
- 在5.1 重大改变
- 在5.0 重大改变
- 搜索和查询DSL改变
- 映射改变
- 过滤器改变
- Suggester变化
- 索引API改变
- 文档API改变
- 设置的改变
- 分配改变
- HTTP改变
- REST API改变
- CAT API改变
- Java API改变
- Packaging
- Plugin改变
- 文件系统相关改变
- 磁盘上数据的路径
- 聚合改变
- 脚本相关改变
- API 规范
- Multiple Indices(多个索引)
- Date math support in index names(索引名称对 Date 和 Math 的支持)
- 常见选项
- URL-based access control(基于 URL 的访问控制)
- Document APIS
- Index API
- Get API
- Update API
- 通过查询 API 更新
- 多个 GET API
- Bulk API
- Reading and Writing documents(读写文档)
- Delete API
- Delete By Query API
- Reindex API
- Term Vectors
- Multi termvectors API
- ?refresh
- Search APIs
- Search
- URI Search
- Request Body Search
- Query
- From / Size
- Sort
- Source filtering
- Fields
- Script Fields
- Doc value Fields
- Post filter
- Highlighting
- Rescoring
- Search Type
- Scroll
- Preference
- Explain
- Version
- Index Boost
- min_score
- Named Queries
- Inner hits
- Search After
- Field Collapsing 字段折叠
- Search 模板
- Multi Search 模板
- Search Shards API
- Suggesters
- Completion Suggester
- Context Suggester
- Phrase Suggester
- Term suggester
- Multi Search API
- Count API
- Validate API
- Explain API
- Profile API
- Profiling Queries
- Profiling Aggregations
- Profiling Considerations
- Aggregations
- Metric Aggregations
- 值计数聚合(Value Count Aggregation)
- 地理边界聚合
- 地理重心聚合
- 基数聚合
- 平均值聚合
- 扩展统计聚合
- 最大值聚合
- 最小值聚合
- Bucket Aggregations
- Children Aggregation
- Date Histogram Aggregation
- Date Range Aggregation
- Diversified Sampler Aggregation
- Filter Aggregation(过滤器聚合)
- Filters Aggregation
- Geo Distance Aggregation(地理距离聚合)
- GeoHash grid Aggregation(GeoHash网格聚合)
- Global Aggregation(全局聚合)
- Histogram Aggregation
- IP Range Aggregation(IP范围聚合)
- Missing Aggregation
- Nested Aggregation(嵌套聚合)
- Range Aggregation(范围聚合)
- Reverse nested Aggregation
- Sampler Aggregation
- Significant Terms Aggregation
- 邻接矩阵聚合
- Pipeline Aggregations
- Avg Bucket Aggregation
- Derivative Aggregation(导数聚合)
- Max Bucket Aggregation
- Min Bucket Aggregation
- Sum Bucket Aggregation
- Stats Bucket Aggregation
- Extended Stats Bucket Aggregation(扩展信息桶聚合)
- Percentiles Bucket Aggregation(百分数桶聚合)
- Cumulative Sum Aggregation(累积汇总聚合)
- Bucket Script Aggregation(桶脚本聚合)
- Bucket Selector Aggregation(桶选择器聚合)
- Serial Differencing Aggregation(串行差异聚合)
- Matrix Aggregations
- Matrix Stats
- Matrix Stats(矩阵统计)
- Caching heavy aggregations(缓存频繁聚合)
- Returning only aggregation results(仅返回需要聚合的结果)
- Aggregation Metadata(聚合元数据)
- Returning the type of the aggregation(返回聚合的类型)
- 索引 API
- Create Index /创建索引
- Delete Index /删除索引
- Get Index /获取索引
- Indices Exists /索引存在
- Open / Close Index API /启动关闭索引
- Shrink Index /缩小索引
- Rollover Index/滚动索引
- Put Mapping /提交映射
- Get Mapping /获取映射
- Get Field Mapping /获取字段映射
- 卷影副本索引
- 依赖卷影副本的节点级设置
- 索引统计信息
- 索引段
- 索引恢复
- 索引分片存储
- 清理缓存
- 刷新
- 同步刷新
- 重新加载
- 强制合并
- cat APIs
- cat aliases
- cat allocation
- cat count
- cat fielddata
- cat health
- cat indices
- cat master
- cat nodeattrs
- cat nodes
- cat pending tasks
- cat plugins
- cat recovery
- cat repositories
- cat thread pool
- cat shards
- cat segments
- cat snapshots
- 集群 API
- Cluster Allocation Explain API
- Cluster Health
- Cluster Reroute
- Cluster State
- Cluster Stats
- Cluster Update Settings
- Nodes hot_threads
- Nodes Info
- Nodes Stats
- Pending cluster tasks
- Task Management API
- 查询 DSL
- 查询和过滤上下文
- Match ALL 查询
- 全文搜索
- 匹配查询
- 短语匹配查询
- 短语前缀匹配查询
- 多字段查询
- 常用术语查询
- 查询语句查询
- 简单查询语句
- 复合查询家族
- Constant Score 查询
- Bool 查询
- Dis Max 查询
- Function Score 查询
- Boosting 查询
- Indices 查询
- Join 查询
- Has Child Query
- Has Parent Query
- Nested Query(嵌套查询)
- Parent Id Query
- 术语查询
- Exists Query(非空值查询)
- Fuzzy Query(模糊查询)
- Ids Query(ID 查询)
- Prefix Query(前缀查询)
- Range Query(范围查询)
- Regexp Query(正则表达式查询)
- Term Query(项查询)
- Terms Query(多项查询)
- Type Query(类型查询)
- Wildcard Query(通配符查询)
- 地理位置查询
- GeoShape Query(地理形状查询)
- Geo Bounding Box Query(地理边框查询)
- Geo Distance Query(地理距离查询)
- Geo Distance Range Query(地理距离范围查询)
- Geo Polygon Query(地理多边形查询)
- Span 查询
- Span Term 查询
- Span Multi Term 查询
- Span First 查询
- Span Near 查询
- Span Or 查询
- Span Not 查询
- Span Containing 查询
- Span Within 查询
- Span Field Masking 查询
- Specialized queries(专业查询)
- Mapping(映射)
- 字段类型
- Array
- Binary
- Range
- Boolean
- Date
- Geo-point datatype
- String
- Text
- Token数
- 渗滤型
- KeyWord
- Nested
- Object
- Numeric
- Meta-Fields(元字段)
- _all field
- _field_names field
- _id field
- _index field
- _meta field
- _parent field
- _routing field
- _source field
- _type field
- _uid field
- Mapping parameters(映射参数)
- analyzer(分析器)
- normalizer(归一化)
- boost(提升)
- Coerce(强制类型转换)
- copy_to(合并参数)
- doc_values(文档值)
- dynamic(动态设置)
- enabled(开启字段)
- fielddata(字段数据)
- format (日期格式)
- ignore_above(忽略超越限制的字段)
- ignore_malformed(忽略格式不对的数据)
- include_in_all(_all 查询包含字段)
- index_options(索引设置)
- index (索引)
- fields(字段)
- Norms (标准信息)
- null_value(空值)
- position_increment_gap(短语位置间隙)
- properties (属性)
- search_analyzer (搜索分析器)
- similarity (匹配方法)
- store(存储)
- Term_vectors(词根信息)
- Dynamic Mapping(动态映射)
- default mapping(mapping中的_default_)
- Dynamic field mapping(动态字段映射)
- Dynamic templates(动态模板)
- Override default template(覆盖默认模板)
- Mapping(映射)
- Analysis
- Tokenizers(分词器)
- Standard Tokenizer(标准分词器)
- Letter Tokenizer
- Lowercase Tokenizer (小写分词器)
- Whitespace Analyzer
- 停止分析器
- UAX URL Email Tokenizer
- Classic Tokenizer
- Thai Tokenizer(泰语分词器)
- NGram Tokenizer
- Keyword Analyzer
- Path Hierarchy Tokenizer(路径层次分词器)
- Pattern Tokenizer
- Token Filters(词元过滤器)
- Apostrophe Token Filter(撇号/单引号过滤器)
- ASCII Folding Token Filter(ASCII Folding 词元过滤器)
- CJK Bigram Token Filter(CJK Bigram词元过滤器)
- CJK Width Token Filter(CJK宽度过滤器)
- Classic Token Filter(经典过滤器)
- Common Grams Token Filter(近义词词元过滤器)
- Compound Word Token Filter(复合词过滤器)
- Decimal Digit Token Filter(十进制数字过滤器)
- Delimited Payload Token Filter(Delimited Payload词元分析器)
- Edge NGram Token Filter(Edge NGram 词元过滤器)
- Elision Token Filter(Elision词元过滤器)
- Fingerprint Token Filter(指纹过滤器)
- Flatten Graph Token Filter(Flatten Graph 词元过滤器)
- Hunspell Token Filter(Hunspell 词元过滤器)
- Keep Types Token Filter(保留指定类型过滤器)
- Keep Words Token Filter(保留字过滤器)
- Keyword Marker Token Filter(Keyword Marker 词元过滤器)
- Keyword Repeat Token Filter(Keyword Repeat 词元过滤器)
- KStem Token Filter(KStem 词元过滤器)
- Length Token Filter(长度词元过滤器)
- Limit Token Count Token Filter(限制词元数量过滤器)
- Lowercase Token Filter(Lowercase 词元过滤器)
- Minhash Token Filter(Minhash过滤器)
- NGram Token Filter(NGram词元过滤器)
- Normalization Token Filter(标准化词元过滤器)
- Pattern Capture Token Filter(模式匹配词元过滤器)
- Pattern Replace Token Filter(模式替换词元过滤器)
- Phonetic Token Filter(Phonetic 词元过滤器)
- Porter Stem Token Filter(Porter Stem 词元过滤器)
- Reverse Token Filteredit(反向词元过滤器)
- Shingle Token Filter(Shingle 词元过滤器)
- Snowball Token Filter(Snowball 词元过滤器)
- Standard Token Filters(标准词元过滤器)
- Stemmer Override Token Filter(Stemmer Override 词元过滤器)
- Stemmer Token Filter(Stemmer 词元过滤器)
- Stop Token Filter(Stop 词元过滤器)
- Synonym Graph Token Filter(Synonym Graph 词元过滤器)
- Synonym Token Filter(Synonym 词元过滤器)
- Trim Token Filter(Trim词元过滤器)
- Truncate Token Filter(截断词元过滤器)
- Unique Token Filter(唯一词元过滤器)
- Uppercase Token Filter(Uppercase词元过滤器)
- Word Delimiter Token Filter(Word Delimiter 词元过滤器)
- Character Filters(字符过滤器)
- md Strip Character Filter
- Mapping Character Filter
- Pattern Replace Character Filter
- Anatomy of an analyzer(分析器的分析)
- Testing analyzers(测试分析器)
- Analyzers(分析器)
- Configuring built-in analyzers(配置内置分析器)
- Standard Analyzer(标准分析器)
- Simple Analyzer(简单分析器)
- 空白分析器
- Stop Analyzer
- 指纹分析器
- 模式分析器
- 自定义分析器
- 语言分析器
- 模块
- Indices(索引)
- Circuit breakers(熔断器)
- Fielddata cache(列数据缓存)
- indexing buffer(索引写入缓冲)
- indices Recovery(索引恢复)
- NetWork Setting(网络配置)
- Node Query Cache(节点查询缓存)
- Shard request cache(分片请求缓存)
- 脚本
- Groovy 脚本语言
- Painless 脚本语言
- Painless 语法
- Painless 调试
- Lucene表达式语言
- 原生(Java)脚本
- 高级文本评分脚本
- 快照和还原
- 线程池
- 传输
- HTTP
- Tribe Node (部落节点)
- 跨集群搜索
- Cluster(集群)
- Disk-based Shard Allocation ( 基于磁盘的分片分配 )
- Shard Allocation Awareness ( 分片分配意识 )
- 群集级别分片分配
- Node
- 插件
- Index Modules(索引模块)
- Analysis(分析)
- 索引分片分配
- 分片分配过滤
- 节点丢失时的延迟分配
- 索引恢复的优先级
- 每个节点的总分片数
- Mapper(映射)
- Merge(合并)
- Similarity module(相似模块)
- Slow log(慢日志)
- Store
- 预加载数据到文件系统缓存
- Translog(事务日志)
- Ingest Node(预处理节点)
- Pipeline Definition(管道定义)
- Ingest APIs
- Put Pipeline API
- Get Pipeline API
- Delete Pipeline API
- Simulate Pipeline API(模拟管道 API)
- Accessing Data in Pipelines(访问管道中的数据)
- Handling Failures in Pipelines(处理管道中的故障)
- Processors(处理器)
- Append Processor(追加处理器)
- Convert Processor(转换处理器)
- Date Processor(日期处理器)
- Date Index Name Processor(日期索引名称处理器)
- Fail Processor(故障处理器)
- Foreach Processor(循环处理器)
- Grok Processor(Grok 处理器)
- Gsub Processor(Gsub 处理器)
- Join Processor(连接处理器)
- JSON Processor(JSON 处理器)
- KV Processor(KV 处理器)
- Lowercase Processor(小写处理器)
- Remove Processor(删除处理器)
- Rename Processor(重命名处理器)
- Script Processor(脚本处理器)
- Set Processor(设置处理器)
- Split Processor(拆分处理器)
- Sort Processor(排序处理器)
- Trim Processor(修剪处理器)
- Uppercase Processor(大写处理器)
- Dot Expander Processor(点扩展器处理器)
- How to(操作方式)
- 一些建议
- Recipes(诀窍)
- 索引速率调优
- 查询优化
- 磁盘使用调优
- Testing(测试)
- Java Testing Framework(测试框架)
- ( why randomized testing ) 为什么随机测试?
- Using the elasticsearch test classes ( 使用 elasticsearch 测试类 )
- unit tests(单元测试)
- integreation test(集成测试)
- Randomized testing(随机测试)
- Assertions()
- Glossary of terms (词汇表)
- Release Notes(版本说明)
- 5.3.0 版本说明
- 5.2.2 Release Notes
- 5.2.1 Release Notes
- 5.2.0 Release Notes
- 5.1.2 Release Notes
- 5.1.1 Release Notes
- 5.1.0 Release Notes
- 5.0.1 Release Notes