Rollover an index
When using a system that manages logs, it is very common to use rolling files for your log entries. Taking this idea, we can have indices that are similar to rolling files.
We can define some conditions to be checked and leave it to Elasticsearch to automatically roll new indices and refer via an alias to only a virtual index.
Getting ready
You need an up-and-running Elasticsearch installation, as used in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command line, you need to install curl
for your operative system.
How to do it…
To enable a rolling index, we need an index with an alias that only points to it. For example, to set a log rolling index we follow these steps:
We need an index with a
logs_write
alias that only points to it:curl -XPUT 'http://127.0.0.1:9200/mylogs-000001' -d ' { "aliases": { "logs_write": {} } }'
The...