Elasticsearch Template 관리

By | 2020년 6월 22일
Table of Contents

Elasticsearch Template 관리

템플릿을 생성해 놓으면 새로 생성되는 인덱스에 설정을 미리 지정해 놓지 않아도 자동으로 템플릿이 적용됩니다.

권장사항

  • Index Template 을 사용하라 : Index를 추가할 때 기본적으로 적용될 템플릿을 만들어라.
  • 모든 신규 템플릿에 적용될 디폴트 템플릿을 만들어라 : 즉 글로벌 세팅을 통해 신규로 추가되는 템플릿에 반드시 적용되도록 하라.

생성되어 있는 템플릿 확인

curl -XGET http://localhost:9200/_cat/templates

생성되어 있는 템플릿 내용확인

curl -XGET http://localhost:9200/_cat/templates/template_web

템플릿 생성

keywordtext 의 차이점은 keyword 는 형태소분석을 하지 않습니다.

또한, 대소문자를 구분합니다. 데이타가 Kate 로 입력되어 있으면 kate 로 검색할 경우 검색이 되지 않습니다.

curl -XPUT http://localhost:9200/_template/template_web?pretty \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "aliases": {},
  "index_patterns": [
    "weblog-one-*",
    "moblog-one-*",
    "scmlog-one-*",
    "scm2log-one-*"
  ],
  "mappings": {
    "doc": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "geoip": {
          "type": "object",
          "dynamic": true,
          "properties": {
            "location": {
              "type": "geo_point"
            },
            "ip": {
              "type": "ip"
            },
            "country_name": {
              "type": "keyword"
            },
            "continent_code": {
              "type": "keyword"
            }
          }
        },
        "@version": {
          "type": "keyword"
        }
      },
      "dynamic_templates": [
        {
          "message_field": {
            "mapping": {
              "type": "text",
              "norms": false
            },
            "match": "message",
            "match_mapping_type": "string"
          }
        },
        {
          "string_fields": {
            "mapping": {
              "type": "text",
              "norms": false,
              "fields": {
                "raw": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              }
            },
            "match": "*",
            "match_mapping_type": "string"
          }
        }
      ]
    }
  },
  "order": 200,
  "settings": {
    "index": {
      "number_of_replicas": "1",
      "number_of_shards": "1",
      "refresh_interval": "5s"
    }
  }
}'

템플릿 삭제

curl -XDELETE http://localhost:9200/_template/template_web?pretty

답글 남기기