美文网首页Elastic Search
ElasticSearch V7.5.2: Root mappi

ElasticSearch V7.5.2: Root mappi

作者: 虹猫日志 | 来源:发表于2020-02-06 16:59 被阅读0次

场景复现

请求地址:put http://127.0.0.1:9200/study ,请求内容如下:

{
    "mappings": {
        "article": {
            "properties": {
                "id": {
                    "type": "long",
                    "store": true,
                    "index":false
                },
                "title": {
                    "type": "text",
                    "store": true,
                    "index":true,
                    "analyzer":"standard"
                },
                "content": {
                    "type": "text",
                    "store": true,
                    "index":true,
                    "analyzer":"standard"
                }
            }
        }
    }
}

异常信息

{
    "error": {
        "root_cause": [
            {
                "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}}}]"
            }
        ],
        "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

解决办法

  1. 不指定索引类型,使用默认索引类型_doc
  2. 如果你要像之前旧版一样兼容自定义 type ,需要携带参数 include_type_name=true,演示图如下:
添加演示

相关文章

网友评论

    本文标题:ElasticSearch V7.5.2: Root mappi

    本文链接:https://www.haomeiwen.com/subject/rkduxhtx.html