ElasticSearch 7.x 报错:Root mapping definition has unsupported parameters

原因:
ElasticSearch 7.x 默认不在支持指定索引类型

以下数据执行put请求:

{
	"settings": {
		"index": {
			"number_of_shards": "2",
			"number_of_replicas": "0"
		}
	},
	"mappings": {
		"person": {
			"properties": {
				"name": {
					"type": "text"
				},
				"age": {
					"type": "integer"
				},
				"mail": {
					"type": "keyword"
				},
				"hobby": {
					"type": "text"
				}
			}
		}
	}
}

报错:

{
error: {
root_cause: [1]
0:  {
type: "mapper_parsing_exception"
reason: "Root mapping definition has unsupported parameters: [person : {properties={mail={type=keyword}, name={type=text}, age={type=integer}, hobby={type=text}}}]"
}-
-
type: "mapper_parsing_exception"
reason: "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [person : {properties={mail={type=keyword}, name={type=text}, age={type=integer}, hobby={type=text}}}]"
caused_by: {
type: "mapper_parsing_exception"
reason: "Root mapping definition has unsupported parameters: [person : {properties={mail={type=keyword}, name={type=text}, age={type=integer}, hobby={type=text}}}]"
}-
}-
status: 400
}

但是对于ElasticSearch 6.x执行时没有问题的,elasticsearch7默认不在支持指定索引类型,默认索引类型是_doc。 官方文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

所以在ElasticSearch 7.x中不指定索引类型,创建索引是成功的:

{
	"settings": {
		"index": {
			"number_of_shards": "2",
			"number_of_replicas": "0"
		}
	},
	"mappings": {
			"properties": {
				"name": {
					"type": "text"
				},
				"age": {
					"type": "integer"
				},
				"mail": {
					"type": "keyword"
				},
				"hobby": {
					"type": "text"
				}
			}
	}
}

在这里插入图片描述
插入数据:
POST http://127.0.0.1:9200/itcast/_bulk


{"index":{"_index":"itcast","_type":"person"}}
{"name":"张三","age": 20,"mail": "111@qq.com","hobby":"羽毛球、乒乓球、足球"}
{"index":{"_index":"itcast","_type":"person"}}
{"name":"李四","age": 21,"mail": "222@qq.com","hobby":"羽毛球、乒乓球、足球、篮球"}
{"index":{"_index":"itcast","_type":"person"}}
{"name":"王五","age": 22,"mail": "333@qq.com","hobby":"羽毛球、篮球、游泳、听音乐"}
{"index":{"_index":"itcast","_type":"person"}}
{"name":"赵六","age": 23,"mail": "444@qq.com","hobby":"跑步、游泳"}
{"index":{"_index":"itcast","_type":"person"}}
{"name":"孙七","age": 24,"mail": "555@qq.com","hobby":"听音乐、看电影"}

出错提示:
mapper [mail] cannot be changed from type [keyword] to [text]

{
took: 188
errors: true
items: [5]
0:  {
index: {
_index: "itcast"
_type: "person"
_id: "RxXQ2HUBJ5PULoSjkfd5"
status: 400
error: {
type: "illegal_argument_exception"
reason: "mapper [mail] cannot be changed from type [keyword] to [text]"
}-
}-
}-
1:  {
index: {
_index: "itcast"
_type: "person"
_id: "SBXQ2HUBJ5PULoSjkfd-"
status: 400
error: {
type: "illegal_argument_exception"
reason: "mapper [mail] cannot be changed from type [keyword] to [text]"
}-
}-
}-
2:  {
index: {
_index: "itcast"
_type: "person"
_id: "SRXQ2HUBJ5PULoSjkfd-"
status: 400
error: {
type: "illegal_argument_exception"
reason: "mapper [mail] cannot be changed from type [keyword] to [text]"
}-
}-
}-
3:  {
index: {
_index: "itcast"
_type: "person"
_id: "ShXQ2HUBJ5PULoSjkfd-"
status: 400
error: {
type: "illegal_argument_exception"
reason: "mapper [mail] cannot be changed from type [keyword] to [text]"
}-
}-
}-
4:  {
index: {
_index: "itcast"
_type: "person"
_id: "SxXQ2HUBJ5PULoSjkfd-"
status: 400
error: {
type: "illegal_argument_exception"
reason: "mapper [mail] cannot be changed from type [keyword] to [text]"
}-
}-
}-
-
}

因为ElasticSearch 7.x 不再支持type。
修改语句如下:

{"index":{"_index":"itcast"}}
{"name":"张三","age": 20,"mail": "111@qq.com","hobby":"羽毛球、乒乓球、足球"}
{"index":{"_index":"itcast"}}
{"name":"李四","age": 21,"mail": "222@qq.com","hobby":"羽毛球、乒乓球、足球、篮球"}
{"index":{"_index":"itcast"}}
{"name":"王五","age": 22,"mail": "333@qq.com","hobby":"羽毛球、篮球、游泳、听音乐"}
{"index":{"_index":"itcast"}}
{"name":"赵六","age": 23,"mail": "444@qq.com","hobby":"跑步、游泳"}
{"index":{"_index":"itcast"}}
{"name":"孙七","age": 24,"mail": "555@qq.com","hobby":"听音乐、看电影"}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值