尝试使用以下命令在Elasticsearch 2下创建映射,但它失败了:
POST /my_blog
{
"settings": {
"index" : {
"number_of_shards" : 10
}
},
"mappings": {
"post" : {
"_routing" : {
"required": false,
"path" : "post_date"
},
"properties": {
"user_id" :{
"type": "integer"
},
"post_text" : {
"type": "string"
},
"post_date": {
"type" : "date",
"format" : "YYYY-MM-DD"
}
}
}
}
}
响应:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Mapping definition for [_routing] has unsupported parameters: [path : post_date]"
}
],
"type": "mapper_parsing_exception",
"reason": "mapping [post]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Mapping definition for [_routing] has unsupported parameters: [path : post_date]"
}
},
"status": 400
}
我为路径,整数/字符串或日期选择的字段无关紧要,它总是给出相同的错误答复(见上文)。有什么想法吗?
答案 0 :(得分:6)
看看type meta-field changes in 2.0。你想做的事情已经不能再做了。
你必须像这样创建索引:
POST /my_blog
{
"settings": {
"index" : {
"number_of_shards" : 10
}
},
"mappings": {
"post" : {
"_routing" : {
"required": false
},
"properties": {
"user_id" :{
"type": "integer"
},
"post_text" : {
"type": "string"
},
"post_date": {
"type" : "date",
"format" : "YYYY-MM-DD"
}
}
}
}
}
然后在每个索引文档的查询字符串中指定路由,例如:
PUT /my_blog/post/1?routing=2015-11-19
{
"user_id": 1,
"post_text": "Lorem ipsum",
"post_date": "2015-11-19"
}