OpenSearch/docs/reference/indices/rollover-index.asciidoc

85 lines
3.1 KiB
Plaintext
Raw Normal View History

2016-06-08 18:32:22 -04:00
[[indices-rollover-index]]
== Rollover Index
The rollover index API allows to switch the index pointed to by an alias given some predicates.
In order to rollover an index, the provided alias has to point to a single index. Upon satisfying
any of the predicates, the alias is switched to point to the rollover index, if the rollover index
already exists, the rollover fails.
2016-06-08 18:32:22 -04:00
This API is syntactic sugar for changing the index pointed to by an alias given some predicate.
The rollover API must be used against an alias that points to a single index:
[source,js]
--------------------------------------------------
$ curl -XPUT 'http://localhost:9200/index1' -d '{
2016-06-08 18:32:22 -04:00
"aliases" : {
"index_alias": {}
}
}'
--------------------------------------------------
To rollover `index_alias` to point to a new index `index2`:
2016-06-08 18:32:22 -04:00
[source,js]
--------------------------------------------------
$ curl -XPOST 'http://localhost:9200/index_alias/_rollover/index2' -d '{
2016-06-08 18:32:22 -04:00
"conditions" : {
"max_age": "7d", <1>
"max_docs": 1000 <2>
}
}'
--------------------------------------------------
<1> Sets a condition that the index has to be at least 7 days old
<2> Sets a condition that the index has to have at least a 1000 documents
The API call above switches the index pointed to by `index_alias` from `index1` to `index2`, if any
of the conditions are met. `index2` is created (using matching <<indices-templates>> if available).
The API call returns immediately if none of the conditions are met.
2016-06-08 18:32:22 -04:00
The rollover API can be used without specifying the name for the new index. In this case, the API requires
the old concrete index name to have `{index_prefix}-{num}` format, as rollover index name is generated
following `{index_prefix}-{num+1}` format.
The `_rollover` API is similar to <<indices-create-index>> and accepts `settings`, `mappings` and
`aliases` to override the index create request for the rollover index.
2016-06-08 18:32:22 -04:00
[source,js]
--------------------------------------------------
$ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{
"conditions" : {
"max_age": "7d",
"max_docs": 1000
},
"settings": { <1>
"index.number_of_shards": 2
}
}'
--------------------------------------------------
<1> Set settings to override matching index template, `mappings` and `aliases` can also be provided.
2016-06-09 11:55:10 -04:00
The rollover API supports `dry_run` mode, where request conditions can be checked without performing the
actual rollover. The `dry_run` mode can be enabled by setting `dry_run=true` as a request parameter.
2016-06-08 18:32:22 -04:00
An example response for the index rollover API:
[source,js]
--------------------------------------------------
{
"old_index": "index-1", <1>
"new_index": "index-2", <2>
"rolled_over": true, <3>
2016-06-09 11:55:10 -04:00
"dry_run": false, <4>
"conditions": { <5>
2016-06-08 18:32:22 -04:00
"[max_age: 7d]": true,
"[max_docs: 1000]": true
}
}
--------------------------------------------------
<1> name of the index the alias was pointing to
<2> name of the index the alias currently points to
<3> whether the alias switch was successful
<4> whether the rollover was dry run
<5> status of the evaluated request conditions
2016-06-08 18:32:22 -04:00