'Template'에 해당되는 글 8건

  1. 2022.07.14 [Elasticsearch] Index Template 사용 시 Mapping 정보 오류
  2. 2020.06.03 [Filebeat] template 설정 setup.template.append_fields
  3. 2018.07.25 [Elasticsearch] Dynamic template - _default_ deprecated.
  4. 2018.07.04 [Elasticsearch] 그냥 settings, mappings, template 예제
  5. 2016.03.02 [Elasticsearch] Create Index Settings & Mappings 템플릿.
  6. 2014.12.05 [Elasticsearch] dynamic template 이란?
  7. 2014.01.08 [Elasticsearch] template 생성 힌트.
  8. 2014.01.07 [elasticsearch] logstash 용 template 샘플.

[Elasticsearch] Index Template 사용 시 Mapping 정보 오류

Elastic/Elasticsearch 2022. 7. 14. 19:30

사용하다 보면 정말 별거 아닌 건데 눈에 잘 안보일 때가 있습니다.

 

에러 메시지)

"reason"=>"failed to parse field [message] of type [text] in document with id '3UI29IEBerapX-zaQi4L'. 
Preview of field's value: 
...중략...
"caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Can't get text on a 
START_OBJECT at 1:529"}

 

이런 에러메시지를 접하게 되면 두 눈 크게 뜨고 Template 에서 정의한 type 정보와 실제 들어 오는 값이 잘 매핑이 되어 있는지 확인을 해보시기 바랍니다.

 

모니터는 큰걸로 글자 크기는 크게 해서 보세요. 

:

[Filebeat] template 설정 setup.template.append_fields

Elastic/Beats 2020. 6. 3. 14:15

참고 문서)

https://www.elastic.co/guide/en/beats/filebeat/current/configuration-template.html

 

설정 중에 필요한 내용이 있어서 기록해 봅니다.

 

setup.template.append_fields

 

A list of fields to be added to the template and Kibana index pattern.

This setting adds new fields. It does not overwrite or change existing fields.

This setting is useful when your data contains fields that Filebeat doesn’t know about in advance.

If append_fields is specified along with overwrite: true,

Filebeat overwrites the existing template and applies the new template when creating new indices.

Existing indices are not affected.

If you’re running multiple instances of Filebeat with different append_fields settings,

the last one writing the template takes precedence.

Any changes to this setting also affect the Kibana index pattern.

 

Example config:

setup.template.overwrite: true

setup.template.append_fields:

  - name: test.name

     type: keyword

  - name: test.hostname

     type: long

 

이 설정으로 dynamic mapping 이나 template 관련 번거로움을 간단하게 해결 할 수 있습니다.

저는 몇 개 field 에 대해서 date 로 설정을 해야 해서 이 설정을 사용했습니다.

 

:

[Elasticsearch] Dynamic template - _default_ deprecated.

Elastic/Elasticsearch 2018. 7. 25. 09:49

늘 그렇지만 다 기억 못합니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/default-mapping.html


_default_ 가 deprecated 되었습니다.


이와 더불어 사용시 아래와 같은 에러가 발생을 경험 할 수 있는데요.


org.elasticsearch.index.mapper.MapperParsingException: Failed to parse mapping [_default_]: No field type matched on [integer], possible values are [object, string, long, double, boolean, date, binary]


"mappings": {
"_default_": {
"dynamic_templates": [
{

...중략...

우선  _default_ 는 다른 type name 을 작성해 주시면 됩니다.

원문에서와 같이 _doc 이나 _log 나 default 와 같은...


그리고 저 위에 에러는 dynamic templates 사용 시 field type 정보를 보시면 이해가 되실 겁니다.

우리가 흔히 알고 있는 mapping field type 과 조금 다르기 때문에 잘 인지 하고 계시면 삽질은 피하실 수 있습니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#match-mapping-type


match_mapping_type

The match_mapping_type matches on the datatype detected by dynamic field mapping, in other words, the datatype that Elasticsearch thinks the field should have. Only the following datatypes can be automatically detected: boolean, date, double, long, object, string. It also accepts * to match all datatypes.


더불어서 잘못 생성된 템플릿을 삭제해야 할 필요가 있습니다.

가끔 아래와 같은 에러가 발생 하는데 이럴 경우 템플릿을 삭제 후 다시 등록 하시면 됩니다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#delete


java.lang.IllegalArgumentException: Rejecting mapping update to [monitoring-20180725] as the final mapping would have more than 1 type: [log, doc]


DELETE /_template/template_1


:

[Elasticsearch] 그냥 settings, mappings, template 예제

Elastic/Elasticsearch 2018. 7. 4. 14:05


[Settings]

"settings":{

  "number_of_shards":1,

  "number_of_replicas":0,

  "index.refresh_interval":"1h",

  "index.routing.allocation.require.box_type":"indexing",

  "index.similarity.default.type":"BM25",

  "index":{

    "analysis":{

      "analyzer":{

        "arirang_custom_analyzer":{

          "tokenizer":"arirang_tokenizer",

          "filter":[

              "lowercase",

              "trim",

              "arirang_synonym",

              "arirang_filter"

            ]

          }

      },

      "filter":{

        "arirang_synonym":{

            "type":"synonym_graph",

            "synonyms":[]

          }

        }

      }

  }

}


[Mappings]

"mappings" : {

  "product": {

    "_source": {

      "enabled": true

    },

    "dynamic_templates": [

      {

        "strings": {

          "match_mapping_type": "string",

          "mapping": {

            "type": "text",

            "analyzer": "arirang_custom_analyzer",

              "fields": {

                "raw": {

                  "type":  "keyword",

                  "ignore_above": 50

                }

            }

          }

        }

      }

    ]

  }

}


:

[Elasticsearch] Create Index Settings & Mappings 템플릿.

Elastic/Elasticsearch 2016. 3. 2. 12:30

그냥 복습 하는 차원에서 기록 합니다.



$ curl -XPUT "http://localhost:9200/INDEX_NAME" -d'

{

  "settings": {

  ...설정할 정보를 넣으세요...

  },

  "mapping": {

  ...설정할 정보를 넣으세요...

  }

}


별 내용 없습니다.

그냥 rest api를 이용해서 index 생성 할 때 필요한 설정 정보를 작성하는 틀 정도 입니다.

type 정보는 mappings 안에 넣으시면 됩니다.

기본적으로 해당 설정은 지정한 INDEX_NAME 에 한해서 적용되는 것입니다. 별도의 global 설정을 하고 싶으시다면 template 기능을 활용하시기 바랍니다.


참고링크)

:

[Elasticsearch] dynamic template 이란?

Elastic/Elasticsearch 2014. 12. 5. 11:12

Elasticsearch에서 제공하는 편리한 기능 중 하나 입니다.

이해하기 위해서는 dynamic mapping 부터 보고 들어 가셔야 합니다.


[원본 링크]

Dynamic mapping

- http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/dynamic-mapping.html


☞ 간단 설명

색인 필드의 데이터에 대한 data type을 지정하지 않고 동적으로 elasticsearch 에서 적절한 type을 지정해 주는 기능 입니다.


예) 

field1:"1" 은 string 으로

field2: 1   은 long 으로 type 맵핑이 됩니다.


그럼 dynamic template 에 대해서 알아 보겠습니다.

elasticsearch에서는 customizing dynamic mapping 하위에 subset으로 기술 되어 있습니다.


[원본 링크]

Dynamic template

- http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html#dynamic-templates


dynamic template 이란?

이 기능은 말 그대로 type mapping 을 사전에 기술해 놓지 않고 동적으로 dynamic mapping에 의해 정의 되는 시점에 동적으로 구성을 하게 되는 내용입니다.


쉽게 말해 mapping type을 미리 선언하지 않고 패턴이나 분석 특성에 맞춰 구성하게 되는 것입니다.

주로 사용하는 경우는 대략 2 가지 정도로 보입니다.


1) 같은 유형의 indice/type을 time series 로 생성 및 관리 할 때 매번 만들지 않고 자동으로 mapping 생성을 하고자 할때.

2) 특정 조건 또는 패턴에 일치하는 field에 대해 자동으로 mapping 속성을 지정하고자 할때.


[_default_]

- 이 type이 dynamic template의 기본 type이 됩니다.

- 별도 구성 없이 동적으로 type을 생성하게 되면 이 정보를 기준으로 mapping type 정의가 됩니다.


내부 properties 설명은 elasticsearch 샘플 자료로 설명을 하겠습니다.


PUT /my_index
{
   
"mappings": {
       
"my_type": {
           
"dynamic_templates": [
               
{ "es": {
                     
"match":              "*_es",
                     
"match_mapping_type": "string",
                     
"mapping": {
                         
"type":           "string",
                         
"analyzer":       "spanish"
                     
}
               
}},
               
{ "en": {
                     
"match":              "*",
                     
"match_mapping_type": "string",
                     
"mapping": {
                         
"type":           "string",
                         
"analyzer":       "english"
                     
}
               
}}
           
]
}}}

- "my_type" 기본 type 이외 사용자가 정의한 type에도 dynamic template 설정이 가능 합니다.

- "match" 는 field에 대한 동적 매칭을 정의 하는 것이며, 패턴 사용이 가능 합니다. 예제에서는 field 명에서 _es 로 끝나는 모든 필드를 의미 합니다.

- "match_mapping_type"은 dynamic mapping 을 통해서 지정된 type 이 뭔지 확인 하는 것입니다. 예제에서는 string 으로 mapping 된 것을 의미 하며, "match"와 함께 해석을 해야 합니다. 즉, *_es 필드명 이어야 하고 string type이면 아래 mapping 정보를 가진다는 의미가 됩니다.

- "mapping"은 type mapping 시 각 field 에 속성을 정의 하게 됩니다. 이 정의 하는 부분에 대한 값을 설정하게 됩니다.


전체적으로 위 예제의 의미는 모든 문자열 필드에 대한 형태소분석기는 english를 적용하고, 필드명에 _es 가 들어간 문자열 필드에 대해서는 형태소분석기로 spanish를 적용하라는 것입니다.


dynamic template 과 mapping 기능은 매우 유용하게 활용이 가능 합니다.

이해 하시는데 도움이 되면 좋겠내요.



:

[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 등의 다른 기능을 활용하기 위해서 인것으로 보입니다.


그럼 이만... :)

:

[elasticsearch] logstash 용 template 샘플.

Elastic/Elasticsearch 2014. 1. 7. 18:55

색인 스키마 관리를 위해서 템플릿 생성을 할 수 있습니다.

쉽게 접할 수 있는 예제로 logstash 정보가 괜찮아 보여서 공유합니다.


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

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates


https://gist.github.com/deverton/2970285

https://github.com/logstash/logstash/blob/v1.3.1/lib/logstash/outputs/elasticsearch/elasticsearch-template.json



{
"template": "logstash-*",
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"index" : {
"query" : { "default_field" : "@message" },
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"_source": { "compress": true },
"dynamic_templates": [
{
"string_template" : {
"match" : "*",
"mapping": { "type": "string", "index": "not_analyzed" },
"match_mapping_type" : "string"
}
}
],
"properties" : {
"@fields": { "type": "object", "dynamic": true, "path": "full" },
"@message" : { "type" : "string", "index" : "analyzed" },
"@source" : { "type" : "string", "index" : "not_analyzed" },
"@source_host" : { "type" : "string", "index" : "not_analyzed" },
"@source_path" : { "type" : "string", "index" : "not_analyzed" },
"@tags": { "type": "string", "index" : "not_analyzed" },
"@timestamp" : { "type" : "date", "index" : "not_analyzed" },
"@type" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}


{
  "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" }
             }
         }
       }
    }
  }
}


: