2.X/6. Modeling Your Data

6-4-08. Index Templates

drscg 2017. 9. 23. 12:59

Elasticsearch doesn’t require you to create an index before using it. With logging, it is often more convenient to rely on index autocreation than to have to create indices manually.

Elasticsearch는 index를 사용하기 전에, index를 생성할 필요가 없다. 로깅에서는, index 자동 생성이, 수동으로 생성하는 것보다, 더 편리하다.

Logstash uses the timestamp from an event to derive the index name. By default, it indexes into a different index every day, so an event with a @timestamp of 2014-10-01 00:00:01 will be sent to the index logstash-2014.10.01. If that index doesn’t already exist, it will be created for us.

Logstash는 index 이름을 만들기 위해, 이벤트의 timestamp를 사용한다. 기본적으로, 매일 다른 index에 색인한다. 따라서, 2014-10-01 00:00:01 라는 @timestamp 를 가진 이벤트는 logstash-2014.10.01 이라는 index로 보내질 것이다. index가 아직 존재하지 않는다면, 생성된다.

Usually we want some control over the settings and mappings of the new index. Perhaps we want to limit the number of shards to 1, and we want to disable the _all field. Index templates can be used to control which settings should be applied to newly created indices:

일반적으로, 새로운 index의 설정과 mapping을 통해, 어떤 제어를 해야 한다. 아마도, shard의 수를 1 로 제한하고, _all field를 비활성화하려 할 것이다. index template은, 새로 생성된 index에 적용되어야 하는 설정을 제어하는데, 사용될 수 있다.

PUT /_template/my_logs 
{
  "template": "logstash-*", 
  "order":    1, 
  "settings": {
    "number_of_shards": 1 
  },
  "mappings": {
    "_default_": { 
      "_all": {
        "enabled": false
      }
    }
  },
  "aliases": {
    "last_3_months": {} 
  }
}

my_logs 라 하는 template을 생성한다.

이 template을 logstash- 로 시작하는 모든 index에 적용한다.

이 template은 더 낮은 order 를 가지는, 기본 logstash template을 무시한다.

primary shard의 수를 1 로 제한한다.

모든 type에 대해 _all field를 비활성화한다.

last_3_months alias에 이 index를 추가한다.

This template specifies the default settings that will be applied to any index whose name begins with logstash-, whether it is created manually or automatically. If we think the index for tomorrow will need more capacity than today, we can update the index to use a higher number of shards.

이 template은 자동 또는 수동으로 생성되는, logstash- 로 시작하는 이름을 가진, 모든 index에 적용할, 기본 설정을 지정한다. 오늘보다 더 많은 용량이 필요한, 내일을 위한 index를 계획한다면, 더 많은 shard의 수를 사용하여, index를 업데이트할 수 있다.

The template even adds the newly created index into the last_3_months alias, although removing the old indices from that alias will have to be done manually.

비록, 기존 index를 해당 alias에서 제거하는 것은 수동으로 해야 하지만, last_3_months alias에 새로 생성된 index를 추가할 수 있다.

'2.X > 6. Modeling Your Data' 카테고리의 다른 글

6-4-06. Multiple Indices  (0) 2017.09.23
6-4-07. Time-Based Data  (0) 2017.09.23
6-4-09. Retiring Data  (0) 2017.09.23
6-4-10. User-Based Data  (0) 2017.09.23
6-4-11. Shared Index  (0) 2017.09.23