場景復現
請求地址:put http://127.0.0.1:9200/test
,請求內容如下:
{
"settings": {
"analysis": {
"analyzer": {
"comma": {
"type": "pattern",
"pattern":","
}
}
}
},
"mappings": {
"doc":{
"properties": {
"text":{
"type": "text",
"analyzer": "comma"
}
}
}
}
}
異常信息
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [doc : {properties={id={index=false, store=true, type=long}, title={analyzer=standard, index=true, store=true, type=text}, content={analyzer=standard, index=true, store=true, type=text}}}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [article : {properties={id={index=false, store=true, type=long}, title={analyzer=standard, index=true, store=true, type=text}, content={analyzer=standard, index=true, store=true, type=text}}}]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [article : {properties={id={index=false, store=true, type=long}, title={analyzer=standard, index=true, store=true, type=text}, content={analyzer=standard, index=true, store=true, type=text}}}]"
}
},
"status": 400
}
失敗原因
ElasticSearch7.x
默認不再支持指定索引類型,默認索引類型是_doc
,如果想改變,則配置 include_type_name: true
即可。注意這一字段將在 8.x
捨棄:
請求隱含:
include_type_name=false
官方原文:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html
解決辦法
- 不指定索引類型,使用默認索引類型
_doc,請求參數修改如下:
{
"settings": {
"analysis": {
"analyzer": {
"comma": {
"type": "pattern",
"pattern":","
}
}
}
},
"mappings": {
"properties": {
"my_text":{
"type": "text",
"analyzer": "comma"
}
}
}
}
2.如果你要像之前舊版一樣兼容自定義 type
,需要攜帶參數 include_type_name=true
,演示圖如下: