[Elasticsearch] template 생성 힌트.

Elastic/Elasticsearch 2014. 1. 8. 18:33

아래 글 참고

http://jjeong.tistory.com/914


이해하기 쉽도록 힌트 몇자 적습니다.

기본 이해는

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html

이 문서를 보시면 됩니다.


step 1.

template 을 생성 합니다.

curl -XPUT localhost:9200/_template/template_1 -d '
{
   
"template" : "te*",
   
"settings" : {
       
"number_of_shards" : 1
   
},
   
"mappings" : {
       
"type1" : {
           
"_source" : { "enabled" : false }
       
}
   
}
}
'

여기서 template : te* 이 의미 하는 것은 index 명입니다.


step 2.

curl -XPUT 'http://localhost:9200/temp/'

이렇게 생성하면 temp 라는 인덱스의 settings/mappings 정보는 template_1 값을 가지게 됩니다.


logstash 예제로 보겠습니다.

아래는 template 생성용 json 입니다.

{
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : "5s",
    "analysis" : {
      "analyzer" : {
        "default" : {
          "type" : "standard",
          "stopwords" : "_none_"
        }
      }
    }
  },
  "mappings" : {
    "_default_" : {
       "_all" : {"enabled" : true},
       "dynamic_templates" : [ {
         "string_fields" : {
           "match" : "*",
           "match_mapping_type" : "string",
           "mapping" : {
             "type" : "multi_field",
               "fields" : {
                 "{name}" : {"type": "string", "index" : "analyzed", "omit_norms" : true, "index_options" : "docs"},
                 "{name}.raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256}
               }
           }
         }
       } ],
       "properties" : {
         "@version": { "type": "string", "index": "not_analyzed" },
         "geoip" : {
           "type" : "object",
             "dynamic": true,
             "path": "full",
             "properties" : {
               "location" : { "type" : "geo_point" }
             }
         }
       }
    }
  }
}

보시면 인덱스 명이 logstash-* 로 시작하는 것들은 이 템플릿을 따르게 됩니다.

_all 을 enable 한 이유는 특정 필드에 대해서 동적으로 검색을 지원하기 위해서 라고 보시면 됩니다.

특히 string 필드에 대해서는 검색을 하는 것으로 지정을 하였고, multi_field 구성한 이유는 not_analyzed 로 봐서는 facet 기능이나 sort 등의 다른 기능을 활용하기 위해서 인것으로 보입니다.


그럼 이만... :)

: