elasticsearch index mapping 에 관한 생각
보통 인덱스를 생성할 때 반드시 인덱스 매핑을 먼저 정의할 것을 권유한다. 매핑 정의서가 있어야 유지 보수가 용이하기 때문이다.
매핑 타입에 맞지 않는 document 를 insert 할 시 어떤 일이 발생하는지 확인해보겠다.
1] 인덱스 정의
#!/bin/bash curl -X PUT 'http://:9200/kim?pretty' -H 'Content-Type: application/json' -d' { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 1 }, "mappings" : { "properties" : { "x" : {"type" : "integer"} } } }' |
2] 데이터 타입에 맞는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/1' -H 'Content-Type: application/json' -d' { "x": 10 }' |
{"_index":"kim","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1}
|
3] 데이터 타입에 맞지 않는 doc를 넣는 경우
#!/bin/bash curl -X POST 'http://:9200/kim/_doc/2' -H 'Content-Type: application/json' -d' { "x": "hello world" }' |
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [x] of type [integer] in document with id '2'","caused_by":{"type":"number_format_exception","reason":"For input string: \"hello world\""}},"status":400} |
4] 결론 : 인덱스를 생성하기 전에 매핑을 정의하는 것이 정신건강에 좋을 꺼라 생각한다.
'ELK > elasticsearch' 카테고리의 다른 글
elasticsearch term query (0) | 2020.12.22 |
---|---|
3노드 클러스터 엘라스틱서치 ( elasticsearch 3node) (0) | 2020.05.09 |
logstash ruby syntax (0) | 2020.04.14 |
logstash file stdin (0) | 2020.04.14 |
보안 적용된 elasticsearch에 쿼리 (0) | 2020.03.22 |