2015-11-19 48 views
7

试图Elasticsearch 2下创建映射使用下面的命令,但它失败:Elasticsearch测绘工作不

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 
} 

不要紧,我选择什么领域的路径,整数/字符串或日期,它总是给出相同的错误答复(见上文)。有任何想法吗?

回答

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" 
} 
+0

谢谢,我要一看。 –

+0

实际上,如果你打算将'routing'标记为不需要的,那么你可以把这个子句放在外面,据我所知。 –