Elasticsearch

Kibana Mapping Conflict 해결 방법

joonsei 2019. 12. 3. 11:14

kibana mapping conflict 현상 발생 시 우선적으로 해결해야 할 두가지 문제

1. index의 기존 데이터 매핑을 수정
2. 새로 만들어지거나, 새로 만들어질 index가 정확한 매핑이 가능하게 수정

but...
Elasticsearch 에서는 이미 인덱싱된 기존 데이터는 매핑을 변경할 수 없다.
기존 데이터를 수정하려면, 새 인덱스를 생성하고 기존데이터를 복사해야 한다 (재 색인화: reindex)

Template Mapping

curl -XPUT 'localhost:9200/_template/access?pretty' -H 'Content-Type: application/json' -d'
{
"index_patterns": [
  "access-*"
],
"settings": {
  "number_of_shards": 5
},
"mappings": {
  "_default_": {
    "dynamic_templates": [
      {
        "gameType": {
          "match": "logType",
          "mapping": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    ]
  }
}
}
'

reindex

curl -XPOST 'localhost:9200/_reindex' -H 'Content-Type: application/json' -d'
{
"source": {
  "index": "access-20191129"
},
"dest": {
  "index": "access-20191129-reindexed"
}
}
'

index delete

curl -XDELETE localhost:9200/access-20191129