Elasticsearch变化太快,版本间的变化也太大,到了7.*版本之后,网上很多文档都失效了,这是个麻烦的事。在网上找了很多文档资料,但在我搭建的7.7版本Elasticsearch中总是报错。花了些时间才找到问题点。如下为创建一个index:test,同时在此索引下创建一个article的type,结果报错Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters.本文地址:http://www.04007.cn/article/838.html,未经许可,不得转载.
#创建Elasticsearch7.*索引: PUT /test { "settings": { "index":{ "refresh_interval": "5s", "number_of_shards" : 12, "number_of_replicas" : 1 } } } #创建索引同时指定analyzer分词器: PUT /test { "settings": { "number_of_shards" : 12, "number_of_replicas" : 1, "analysis":{ "analyzer":{ "ik":{ "tokenizer":"ik_max_word" } } } }, "mappings":{ "article":{ "properties":{ "id":{ "type":"long" }, "title":{ "type":"text", "analyzer": "ik_max_word" }, "content":{ "type":"text", "analyzer": "ik_max_word" } } } } } #报错:Root mapping definition has unsupported parameters: [article { "error" : { "root_cause" : [ { "type" : "mapper_parsing_exception", "reason" : "Root mapping definition has unsupported parameters: [article : {properties={id={type=keyword}, title={analyzer=ik_max_word, type=text}, content={analyzer=ik_max_word, type=text}}}]" } ], "type" : "mapper_parsing_exception", "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [article : {properties={id={type=keyword}, title={analyzer=ik_max_word, type=text}, content={analyzer=ik_max_word, type=text}}}]", "caused_by" : { "type" : "mapper_parsing_exception", "reason" : "Root mapping definition has unsupported parameters: [article : {properties={id={type=keyword}, title={analyzer=ik_max_word, type=text}, content={analyzer=ik_max_word, type=text}}}]" } }, "status" : 400 }本文地址:http://www.04007.cn/article/838.html,未经许可,不得转载.
原来Elasticsearch从7.4版本起默认不再支持指定索引类型,所有的索引其默认索引类型就是_doc(隐含:include_type_name=false)。那为什么type类型要被移除呢?我想Elasticsearch也许通过此举让我们更能明白type的意义,平常大家喜欢把索引和关系数据库的库对比,而把type类型和表对比。但这是一个不正确的。表是相互独立的。但在type类型里字段是相互关联着的,Elasticsearch索引中所有不同类型的同名字段内部使用的是同一个lucene字段存储,两个类型里的user_name必须有一样的字段定义。在同一个索引中,存储仅有小部分字段相同或者全部字段都不相同的文档,会导致数据稀疏,影响Lucene有效压缩数据的能力。所以Elasticsearch7移除了类型的概念。本文地址:http://www.04007.cn/article/838.html,未经许可,不得转载.
而对于上面的这段创建代码,需要修改:mappings下不再需要一层type类型,即一个索引下面的所有type都用的同一个公共的_doc。如下:本文地址:http://www.04007.cn/article/838.html,未经许可,不得转载.
#创建索引并带IK分词 PUT /test { "settings": { "number_of_shards" : 12, "number_of_replicas" : 1, "analysis":{ "analyzer":{ "ik":{ "tokenizer":"ik_max_word" } } } }, "mappings":{ "properties":{ "id":{ "type":"long" }, "title":{ "type":"text", "analyzer": "ik_max_word" }, "content":{ "type":"text", "analyzer": "ik_max_word" } } } }本文地址:http://www.04007.cn/article/838.html,未经许可,不得转载.
本文地址:http://www.04007.cn/article/838.html 未经许可,不得转载. 手机访问本页请扫描右下方二维码.
![]() |
![]() |
手机扫码直接打开本页面 |