LoginSignup
2
2

More than 1 year has passed since last update.

ElasticsearchにおけるMapping の使い方

Last updated at Posted at 2021-12-24

1. そもそもMappingの確認/登録はどうやるの

■ Mappingを登録するとき

Mappingに関するJSONをPUTで投げるだけ。

PUT /test_index
{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "team": { 
        "type": "text",
        "fields": {
          "raw": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

■ Mappingを確認するとき

Mappingに関するGETで投げると、Mappingに関するJSONが返ってくる。

GET /test_index/_mapping?pretty

# レスポンス
{
   "test_index": {
      "mappings": {
         "properties": {
            "name": {
               "type": "text"
            },
            "team": {
               "type": "text",
               "fields": {
                    "raw": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                }
             }
         }
      }
   }
}

2. Mappingの読み方

データ・タイプは複数指定できる

 取り込みデータ.json
{
   "name":"hogehoge",
   "team":"A"
}

図1.png

データに連想配列があるとき

 取り込みデータ.json
{
   "name":"hogehoge",
    [
       {
          "team":"A",
          "position":"wingback"
       },
       {
          "team":"B",
          "position":"goalkeeper"
       }
     ]
}

図2.png

メモ

curlでも投げられる。KibanaのDevToolにcurl -XGET /test/_mapping?pretty
をコピペすると自動的に、GET /test/_mapping?prettyにしてくれる。なんだこの機能。

参考

2
2
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
2
2