Tech 기록지/Elastic Stack
[ElasticStack-24] elasticsearch & logstash template (shard setting)
Lio Grande
2020. 7. 1. 10:13
일반적으로 Logstash에서 파일을 인덱싱하게 되면 ELK 7.0 이상 버전에서는 shard 가 1의 값을 디폴트로 가진다 (6.x 이하 버전은 shard 개수 5가 디폴트)
만약 어떤 인덱스가 ES에 적재된 후, shard 개수를 변경하려면 _reindex로 새 인덱스를 생성하는 것 말고는 답이 없다.
그래서 아예, 인덱싱 전에 템플릿을 작성하여 샤드를 조정할 수 있는 기능을 ES에서 제공한다. 다음을 보자.
(참고 : https://www.elastic.co/guide/en/elasticsearch/reference/6.4/indices-templates.html)
# curl -X PUT "localhost:9200/_template/template_1?pretty" -H 'Content-Type: application/json' -d'
PUT _template/template_1
{
"index_patterns": ["te*", "bar*"],
"settings": {
"number_of_shards": 1
},
"mappings": {
"_doc": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
}
'
ES 에서는 _template 기능을 통해 특정 규격의 인덱스를 생성할 수 있다. 위 예제의 항목들을 간단히 설명하면 다음과 같다.
1. template_1 : 템플릿의 ID.
2. index_patterns : 인덱스명이 패턴과 같다면 템플릿을 자동으로 세팅해준다.
예를 들면, 위 예제에서 "te*", "bar*" 라는 두 패턴의 인덱스에 대해서는 템플릿이 적용되는데, 이때 가능한 인덱스는 다음과 같은 형태다.
# "te*" 패턴의 가능 인덱스명
test
tech
teenager
tetete
...
# "bar*" 패턴의 가능 인덱스명
bars
barber
barracuda
barbarbar
...