Elasticsearch template 추가하기
Logstash를 통해서 데이터를 자동으로 받고 있기 때문에
인덱스 생성을 날짜(월 단위)로 자동 생성하고 있다.
인덱스 생성을 자동으로 하다보니 맵핑에 대한 문제가 생겼는데,
Template기능을 사용하면 인덱스 생성시 Template를 먼저 확인하고
그 조건에 맞는 방식으로 생성한다.
curl -XPUT 'localhost:9200/_template/template_1' -H 'Content-Type: application/json' -d '
{
"index_patterns" : ["TEST-*"],
"order" : 2,
"mappings": {
"_doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"action": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}'
index_patterns에 따라서 생성되는 인덱스를 참고 할 지 안할지 설정 할 수 있다.
order를 설정해주면, order가 높은 숫자로 덮어쓰기가 가능하다.
template 를 확인 할 때는
curl -XGET 'localhost:9200/_template/template_1?pretty'
이렇게 확인하면 된다.