티스토리 뷰

[업데이트 2017.02.14 11:15]

 

Elasticsearch로 입력하는 데이터의 field가 많고, 특정 field는 number로 변환이 되어야 하는 경우에 _default_ mapping에 numeric_detection를 true로 설정하여 사용합니다. 그러나 version 체계(예: 1.00)를 명시하는 field의 경우 Elasticsearch에 입력시 잘못된 데이터 타입 변환으로 아래와 같이 오류가 발생할 때가 있습니다.

 

:response=>
{
	"index"=>
		{"_index"=>"logstash-data-2016.01", 
		"_type"=>"data", 
		"_id"=>"14173638", 
		"status"=>400, 
		"error"=>
			{	"type"=>"illegal_argument_exception", 
				"reason"=>"mapper [Data.OSVersion] of different type, current_type [text], merged_type [float]"
			}
		}
	}
}

 

그럴때는 추가로 dynamic_templates를 이용하여 명시적으로 text type로 변환되도록 지정합니다. path_match를 이용하여 해당 데이터 field에 대해 인식 및 변환되도록 지정하였습니다.

 

PUT _template/logstash_data
{
    "template": "logstash-data-*",
    "settings": {
      "index": {
        "number_of_shards": "3",
        "number_of_replicas": "1",
        "mapping": {
          "total_fields": {
            "limit": "4000"
          }
        }
      }
    },
    "mappings": {
      "_default_": {
        "numeric_detection": true,
        "dynamic_templates": [
          {
            "texts": {
              "path_match": "Data.OSVersion",
              "mapping": {
                "type": "text"
              }
            }
          }
        ],
        "_all": {
          "enabled": true
        }
      
      }
  }
}

 

Elastichsearch에 데이터 입력시 numeric detection > dynamic_templates 순으로 데이터 맵핑이 적용 됨을 확인 할 수 있습니다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함