1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elasticsearchのmappingのkey名とtype名は合わせること

1
Last updated at Posted at 2014-06-18

Elasticsearchでは、あるtypeのmappingを以下のようなAPIで定義できるが、
type名(article)とjsonのkey名を一致させる必要があるらしい。

# test1というindexにarticleというtypeを定義
$ curl -XPUT 'http://localhost:9200/test1/article/_mapping' -d '@article.json'

つまり

//これはOK
// article.json
{
    article : {
        properties : {
            article_id : {
                type : "string",
                index : "not_analyzed"
            },
            title : {
                type : "string"
            }
        }
    }
}

//これはNG
// article.json
{
    hoge : {
        properties : {
            article_id : {
                type : "string",
                index : "not_analyzed"
            },
            title : {
                type : "string"
            }
        }
    }
}

検証ログ

$ elasticsearch -v
Version: 1.0.0, ...
 
# jsonのpropertiesの親のkeyはhoge
$ cat article.json
{
    hoge : {
        properties : {
            article_id : {
                type : "string",
                index : "not_analyzed"
            },
            title : {
                type : "string"
            }
        }
    }
}
 
# test1というindexに、articleというtypeを定義
$ curl -XPUT 'http://localhost:9200/test1/article/_mapping' -d '@article.json'
{"ok":true,"acknowledged":true}
 
# 定義できてない。。
$ curl -XGET 'http://localhost:9200/test1/article/_mapping'
{
    "test1":{
        "mappings":{
            "article":{
                "properties":{}
            }
        }
    }
}

0.90系での検証

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?