DBAtlas · 데이터베이스 운영 아틀라스

component template으로 인덱스 템플릿 구성 및 결과 시뮬레이션

Elasticsearch인덱스 수명 주기

명령어

PUT _component_template/app-mappings
{
  "template": {
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "@timestamp": { "type": "date" },
        "level": { "type": "keyword" },
        "msg": { "type": "text" }
      }
    }
  }
}
PUT _index_template/app-events
{
  "index_patterns": ["app-events-*"],
  "priority": 500,
  "composed_of": ["app-mappings"],
  "template": { "settings": { "number_of_shards": 1, "refresh_interval": "5s" } }
}
# See the final settings and mapping before the index is created:
POST _index_template/_simulate_index/app-events-000001
GET _cat/templates?v&s=name

하는 일

재사용 가능한 매핑 component template을 정의하고 이를 인덱스 템플릿으로 조합하며, 인덱스를 만들지 않고 주어진 인덱스 이름에 적용될 최종 설정과 매핑을 보여 준다.

사용 시점

새 인덱스가 잘못된 매핑이나 샤드 수로 생성될 때(dynamic mapping 폭증, keyword 대신 text), 그리고 템플릿 변경을 배포하기 전.

주의

템플릿은 새로 생성되는 인덱스에만 적용되며 기존 인덱스의 매핑은 바뀌지 않는다(reindex-alias-swap 참고). 두 템플릿이 같은 패턴에 일치하면 priority가 가장 높은 하나만 사용되며 병합되지 않는다. dynamic: strict는 정의되지 않은 필드가 포함된 문서를 거부하므로 애플리케이션이 새 필드를 보내면 인덱싱이 실패한다.

DBAtlas에서 열기 →

관련 항목