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":{}
}
}
}
}