How to do it…

To enable a rolling index, we need an index with an alias that points to it alone. For example, to set a log rolling index, we would follow these steps:

  1. We need an index with a logs_write alias that points to it alone:
PUT /mylogs-000001
{
"aliases": {
"logs_write": {}
}
}

The result will be an acknowledgement, as follows:

{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "mylogs-000001"
}
  1. We can add the rolling to the logs_write alias in this way:
POST /logs_write/_rollover
{
"conditions": {
"max_age": "7d",
"max_docs": 100000
},
"settings": {
"index.number_of_shards": 3
}
}

The result will be as follows:

{
"acknowledged" : false,
"shards_acknowledged" : false,
"old_index" : "mylogs-000001",
"new_index" : "mylogs-000002",
"rolled_over" : false,
"dry_run" : false,
"conditions" : {
"[max_docs: 100000]" : false,
"[max_age: 7d]" : false
}
}
  1. In case your alias doesn't point to a single index, a similar error is returned:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "source alias maps to multiple indices
}
],
"type" : "illegal_argument_exception",
"reason" : "source alias maps to multiple indices"
},
"status" : 400
}