Skip to content

Instantly share code, notes, and snippets.

@tatsunori-nishikori
Last active June 20, 2017 02:29
Show Gist options
  • Save tatsunori-nishikori/f7a1867d8b225b052855cc5977bd2824 to your computer and use it in GitHub Desktop.
Save tatsunori-nishikori/f7a1867d8b225b052855cc5977bd2824 to your computer and use it in GitHub Desktop.
ElasticSearchでmappingの更新

ドキュメントどおりindexでPUTしたらエラーになる

{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"rettrmt"}],"type":"index_already_exists_exception","reason":"already exists","index":"rettrmt"},"status":400}

すでにあるやつはUpdate出来ないっぽい

更新したいタイプがなければ下記のようにしたら良さそう

curl -XPUT 'http://10.56.139.61:9200/rettrmt/_mapping/RETTRMT' -d '
{
  "properties": {
    "actor_id": { // or whichever properties you want to add
            "type": "string",
            "index": "not_analyzed"
    }
  }
}
curl -XPUT 'localhost:9200/twitter?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "tweet": {
      "properties": {
        "message": {
          "type": "text"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/twitter/_mapping/user?pretty' -H 'Content-Type: application/json' -d'
{
  "properties": {
    "name": {
      "type": "text"
    }
  }
}
'
curl -XPUT 'localhost:9200/twitter/_mapping/tweet?pretty' -H 'Content-Type: application/json' -d'
{
  "properties": {
    "user_name": {
      "type": "text"
    }
  }
}
'
  • 例: account-suggest Typeを追加する
curl -XPUT "localhost:9200/bank/_mapping/account-suggest" -d '
{
      "properties": {
        "suggest": {
          "type": "completion"
        },
        "address": {
          "type": "text"
        }
      }
}
'
  • 参考

https://stackoverflow.com/questions/35838208/recreation-of-mapping-elastic-search-

  • 無停止でindexを張り替える技

https://www.elastic.co/blog/changing-mapping-with-zero-downtime

Cookpad blog http://techlife.cookpad.com/entry/2015/09/25/170000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment