新建索引
PUT forum
{
"mappings": {
"article" : {
"properties" : {
"articleID" : {
"type" : "keyword"
}
}
}
}
然后,报错: Root mapping definition has unsupported parameters: [article : {properties={articleID={type=keyword}}}]
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [article : {properties={articleID={type=keyword}}}]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [article : {properties={articleID={type=keyword}}}]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [article : {properties={articleID={type=keyword}}}]"
}
},
"status" : 400
}
查看官网示例后发现 7.X 默认不在支持指定索引类型,默认索引类型是_doc(隐含:include_type_name=false)。见官网: Removal of mapping types 修改:
PUT forum
{
"mappings": {
"properties" : {
"articleID" : {
"type" : "keyword"
}
}
}
返回响应
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "forum"
}
如果你要像之前旧版版本一样兼容自定义 type ,需要将 include_type_name=true 携带, 见官网示例: index templates
重建索引
#注意:这里是把索引删了,数据也就没了
DELETE forum
PUT forum?include_type_name=true
{
"mappings": {
"article" : {
"properties" : {
"articleID" : {
"type" : "keyword"
}
}
}
}
返回响应
#! Deprecation: [types removal] Using include_type_name in create index requests is deprecated. The parameter will be removed in the next major version.
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "forum"
}
但是这一字段将在8.x 舍弃