본문 바로가기

프로그래밍/Elastic Stack

[ElasticSearch] index mapping 변경하기.

1. 개요

 - ElasticSearch를 사용하던 중 index mapping을 변경 해야하는 문제가 발생.

 - 재인덱싱(reindex)을 해야한다.

 - 데이터 양이 있어, 재인덱싱 시간이 길다.

 - ........

 - alias를 활용해 보자!


2. 기본작업

 1) Alias 만들기 

  - test_v1 이라는 index에 test라는 alias를 만든다.


curl -XPOST 'http://localhost:9200/_aliases' -d '

{

    "actions" : [

        { "add" : 

          { 

            "index" : "test_v1", 

            "alias" : "test" 

          } 

        }

    ]

}'


 2) Alias 확인

  - 호출

curl -XGET 'http://localhost:9200/test?pretty=true'


 - 결과 

{

  "test": {

    "aliases": {

      "test_v1": {}

    }

}


 3) Application

 - Application에서 바라보는 index를 alias로 만든 test로 변경한다.


3. 새롭게 작업할 index를 생성 작업 한다.


4. Alias를 변경한다.

curl -XPOST localhost:9200/_aliases -d '

{

    "actions": [

        { "remove": {

            "alias": "test",

            "index": "test_v1"

          }

        },

        { "add": {

            "alias": "test",

            "index": "test_v2"

            }

        }

    ]

}

'


5. Alias 확인

 - 호출

curl -XGET 'http://localhost:9200/test?pretty=true'


 - 결과

{

  "test": {

    "aliases": {

      "test_v2": {}

    }

}