Lab 7.1: Data management concepts
Objective:
In this lab, you will work with index aliases and templates to create a time-series index that can leverage rollover.
-
Within Kibana, go to Stack Management -> Index Management.
-
Define a new component template that satisfies the following requirements:
- the name of the component template is
time-series-mappings - there are three mapped fields defined:
- a
@timestampfield of type Date - a
statusfield of type Keyword - a
messagefield of type Text
- a
Solution
- Open the component template tab.
- Click Create component template
- Name your component template , and click Next
- On the Index Settings page, click Next
- On the Mappings page, add the following mappings:
- a
@timestampfield of typeDate - a
statusfield of typeKeyword - a
messagefield of typeText
- a
- Click Next when the three fields are defined
- On the Aliases page, click Next
- On the Review page, click Create component template
Alternatively, you can run the following command in Console:
PUT _component_template/time-series-mappings { "template": { "mappings": { "properties": { "@timestamp": { "type": "date" }, "status": { "type": "keyword" }, "message": { "type": "text" } } } } } - the name of the component template is
-
EXAM PREP: Create a new index template that satisfies the following requirements:
- the name of the index template is
my-metrics-template - the index pattern matches any index that starts with the name
my-metrics- - set the priority to 500
- the index template uses your
time-series-mappingcomponent template
Solution
- Click the Index Templates tab, and then click Create template
- Name your template
my-metrics-template - Set the index pattern to
my-metrics-* - Set priority to 500, and leave everything else as default
- Click Next
- On the next screen, add the
time-series-settingscomponent template you created by cliking the+symbol next to the component - Click Next until you get to the Review screen, then click Create template
Alternatively, you can run the following command in Console:
PUT _index_template/my-metrics-template { "priority": 500, "index_patterns": [ "my-metrics-*" ], "composed_of": [ "time-series-mappings" ] } - the name of the index template is
-
In Console, run the following to confirm your template is appropriately defined:
The output should look like this:POST _index_template/_simulate_index/my-metrics-test{ "template" : { "settings" : { "index" : { "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } } } }, "mappings" : { "properties" : { "@timestamp" : { "type" : "date" }, "message" : { "type" : "text" }, "status" : { "type" : "keyword" } } }, "aliases" : { } }, "overlapping" : [ ] } -
Create a second component template named
time-series-settingsthat sets thenumber_of_replicasto2.Solution
Add the
number_of_replicasvalue to the index settings page of the component template wizard:Here is the command if you want to use Console:{ "number_of_replicas": 2 }PUT _component_template/time-series-settings { "template": { "settings": { "index": { "number_of_replicas": "2" } } } } -
Update the
my-metrics-templateto use your newtime-series-settingscomponent.Solution
If you are using Console:
PUT _index_template/my-metrics-template { "priority": 500, "index_patterns": [ "my-metrics-*" ], "composed_of": [ "time-series-mappings", "time-series-settings" ] } -
Test that your new template settings have been applied by rerunning the following command:
The output should now look like this:POST _index_template/_simulate_index/my-metrics-test{ "template" : { "settings" : { "index" : { "number_of_replicas" : "2", "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } } } }, "mappings" : { "properties" : { "@timestamp" : { "type" : "date" }, "message" : { "type" : "text" }, "status" : { "type" : "keyword" } } }, "aliases" : { } }, "overlapping" : [ ] } -
Create a new index named
my-metrics-000001configured to be the write index for themy-metricsalias. Please view the details of your new index and verify it has all the correct settings from the index template.Solution
PUT my-metrics-000001 { "aliases": { "my-metrics": { "is_write_index": true } } } GET my-metrics-000001 -
Let's try a rollover! Call the rollover API with the
my-metricsalias and set maximum age of 2 seconds.Solution
POST my-metrics/_rollover { "conditions": { "max_age": "2s" } } -
Use a
GET my-metricsto confirm that there are now two indices in the alias and the newmy-metrics-000002index is now the write index.
Summary:
In this lab, you saw how to define an index template that uses component templates. You also saw how to perform a simple rollover operation.