LoginSignup
13
12

More than 5 years have passed since last update.

Elasticsearchのインデックス再構築

Last updated at Posted at 2016-05-11

Elasticsearchのインデックスを再構築(再作成)する手順
マッピングの定義を変更するにあたってインデックスの再構築が必要。

elasticsearch バージョン1.5.1で動作確認

1. マッピング定義用のjsonファイルをつくる

mapping.json

{
  "mappings" : {
    "test" : {
      "properties" : {
        "title" : {
          "type" : "string",
          "index" : "not_analyzed"
        }
      }
    }
  }
}

2. マッピング定義用のファイルを元に新しいインデックスつくる

$ curl -XPOST localhost:9200/new_index -d @./mapping.json

3. 新しいインデックスに既存データを移行する

これを使う
https://github.com/geronime/es-reindex

$ ./es-reindex.rb http://localhost:9200/old_index http://localhost:9200/new_index

4. エイリアスを旧→新に切り替える

古いインデックス(old_index)のエイリアスを削除し、新しいインデックス(new_index)にエイリアスをつける

$ curl -XPOST localhost:9200/_aliases -d '
{
  "actions": [
    { "remove": { "index": "old_index", "alias": "index_alias" } }, 
    { "add" : { "index": "new_index", "alias": "index_alias" } }
  ]
}
'
13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12