LoginSignup
6
4

More than 5 years have passed since last update.

ElasticsearchのDynamicTemplateのメモ

Last updated at Posted at 2018-07-17

Elasticsearchを使う機会があって、
DynamicTemplateを使用したので、そのときのメモです。
メモなので雑です。

DynamicTemplateは、elasticsearchにデータをアップロードする際、
elasticsearchが自動でフィールドの型設定をしてくれるのですが、
特定の文字列にマッチする場合に、適用する設定のことです。

つまり
「このindexに、この名前でデータがアップロードされたら、こうしてね」
ということですね。

path_to_apply_*の中にある、「text_*」に該当するものは日本語解析可能にする」
という設定のjson

mapping_template.json
{
  "template": "path_to_apply*",
  "settings": {
    "index": {
      "analysis": {
        "tokenizer": {
          "kuromoji_user_dict": {
            "type": "kuromoji_tokenizer",
            "mode": "serach"
          }
        }
      }
    }
  },
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "named_analyzers": {
            "match_mapping_type": "string",
            "match": "text_*",
            "mapping": {
              "fielddata": true,
              "analyzer": "kuromoji",
              "fields": {
                "keyword": {
                  "type": "keyword"
                }
              }
            }
          }
        }
      ]
    }
  }
}

以下のコマンドで適用します。

$ curl -X PUT 'endpoint:port/_template/path_to_apply' -d @mapping_template.json
6
4
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
6
4