# Rollover Index/滚动索引
原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html)
译文链接 : [Rollover Index/滚动索引](/pages/viewpage.action?pageId=4882801)
贡献者 : [Le-Mon](/display/~tanwen)
当现有索引被认为太大或太旧时,滚动索引API会将别名滚动到新的索引。
API接受单个别名和条件列表。 别名只能指向一个索引。 如果索引满足指定的条件,则创建一个新的索引,并将别名切换到指向新的索引。
```
curl -XPUT 'localhost:9200/logs-000001 ?pretty' -d'
{
"aliases": {
"logs_write": {}
}
}'
# Add > 1000 documents to logs-000001
curl -XPOST 'localhost:9200/logs_write/_rollover ?pretty' -d'
{
"conditions": {
"max_age": "7d",
"max_docs": 1000
}
}'
```
| [![](https://img.kancloud.cn/89/2e/892e2d6105d4361c3e81583c8e019d23_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO122-1) | 创建索引 `logs-0000001` 别名为 `logs_write`. |
| [![](https://img.kancloud.cn/50/46/50466ab92768bfee2306a5da100c7496_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO122-2) | 如果 ogs_write 指向的索引是在7天以前创建的,或者包含1000个以上的文档,则会创建 logs-000002索引,并更新logs_write别名以指向logs-000002. |
上述可能会返回如下的响应:
```
{
"acknowledged": true,
"shards_acknowledged": true,
"old_index": "logs-000001",
"new_index": "logs-000002",
"rolled_over": true,
"dry_run": false,
"conditions": {
"[max_age: 7d]": false,
"[max_docs: 1000]": true
}
}
```
| [![](https://img.kancloud.cn/89/2e/892e2d6105d4361c3e81583c8e019d23_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO123-1) | index 是否被滚动. |
| [![](https://img.kancloud.cn/50/46/50466ab92768bfee2306a5da100c7496_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO123-2) | Whether the rollover was dry run. |
| [![](https://img.kancloud.cn/59/09/59090687855ebb833c063fe09e622609_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO123-3) | 条件的列表. |
## Naming the new index/新索引名称
如果现有索引的名称以 - 和数字结尾。 logs-000001 - 然后新索引的名称将遵循相同的模式,增加数字(logs-000002)。 无论旧索引名称如何,编号为零填充长度为6。
如果旧名称与此模式不匹配,则必须按照如下所示,指定新索引的名称:
```
curl -XPOST 'localhost:9200/my_alias/_rollover/my_new_index_name?pretty' -d'
{
"conditions": {
"max_age": "7d",
"max_docs": 1000
}
}'
```
## Using date math with the rolllover API/使用滚动API的日期计算
使用[日期计算](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html "Date math support in index names"): 根据索引滚动的日期来命名滚动索引是有用的技术,例如 `logstash-2016.02.03`.。 滚动API支持日期,但要求索引名称以一个破折号后跟一个数字,例如 logstash-2016.02.03-1,每次索引滚动时都会增加。 例如
```
# PUT /<logs-{now/d}-1> with URI encoding:
curl -XPUT 'localhost:9200/%3Clogs-%7Bnow%2Fd%7D-1%3E ?pretty' -d'
{
"aliases": {
"logs_write": {}
}
}'
curl -XPUT 'localhost:9200/logs_write/log/1?pretty' -d'
{
"message": "a dummy log"
}'
# Wait for a day to pass
curl -XPOST 'localhost:9200/logs_write/_rollover ?pretty' -d'
{
"conditions": {
"max_docs": "1"
}
}'
```
| [![](https://img.kancloud.cn/89/2e/892e2d6105d4361c3e81583c8e019d23_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO124-1) | `创建当日的索引 logs-2016.10.31-1` |
| [![](https://img.kancloud.cn/50/46/50466ab92768bfee2306a5da100c7496_14x15.jpg)](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html#CO124-2) | 当日索引滚动, 立即生成如. `logs-2016.10.31-000002` , 或者 `logs-2016.11.01-000002` 24小时后 |
然后可以按照 [日期数学文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html "Date math support in index names") 中的描述来引用这些索引。 例如,要搜索过去三天创建的索引,您可以执行以下操作:
```
# GET /<logs-{now/d}-*>,<logs-{now/d-1d}-*>,<logs-{now/d-2d}-*>/_search
curl -XGET 'localhost:9200/%3Clogs-%7Bnow%2Fd%7D-*%3E%2C%3Clogs-%7Bnow%2Fd-1d%7D-*%3E%2C%3Clogs-%7Bnow%2Fd-2d%7D-*%3E/_search?pretty'
```
## Defining the new index/定义新索引
新索引的设置,映射和别名取自任何匹配的[索引模板](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html "Index Templates")。 此外,您可以在请求正文中指定设置,映射和别名,就像 [create index](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html "Create Index") API一样。 请求中指定的值覆盖匹配索引模板中设置的任何值。 例如,以下滚动请求将覆盖index.number_of_shardssetting:
```
curl -XPUT 'localhost:9200/logs-000001?pretty' -d'
{
"aliases": {
"logs_write": {}
}
}'
curl -XPOST 'localhost:9200/logs_write/_rollover?pretty' -d'
{
"conditions" : {
"max_age": "7d",
"max_docs": 1000
},
"settings": {
"index.number_of_shards": 2
}
}'
```
## Dry run/干运行
滚动API支持dry_run模式,可以在不执行实际滚动的情况下检查请求条件:
```
curl -XPUT 'localhost:9200/logs-000001?pretty' -d'
{
"aliases": {
"logs_write": {}
}
}'
curl -XPOST 'localhost:9200/logs_write/_rollover?dry_run&pretty' -d'
{
"conditions" : {
"max_age": "7d",
"max_docs": 1000
}
}'
```
## Wait For Active Shards/等待激活分片
因为滚动操作会创建一个新的索引,因此在创建索引时的wait_for_active_shards 设置也适用于滚动操作。
- 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