The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.

Posted AresCarry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.相关的知识,希望对你有一定的参考价值。

一、前言

在创建es索引的时候,会遇到这样的错误:

创建语句:


PUT /griffin
{
    "aliases": {},
    "mappings": {
      
        "_doc": {
            "properties": {
                "name": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "tmst": {
                    "type": "date"
                }
            }
        }
    },
    "settings": {
        "index": {
            "number_of_replicas": "2",
            "number_of_shards": "5"
        }
    }
}
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
  },
  "status": 400
}

原因是:不能在type类型上创建映射 , 在es7中已经在内部取消了, type。

二、解决方案

去掉 _doc , 就可以了

PUT /griffin
{
    "aliases": {},
    "mappings": {
    
            "properties": {
                "name": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "tmst": {
                    "type": "date"
                }
            }
    },
    "settings": {
        "index": {
            "number_of_replicas": "2",
            "number_of_shards": "5"
        }
    }
}

以上是关于The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.的主要内容,如果未能解决你的问题,请参考以下文章

springboot整合gson打开swagger报错:Unable to render this definition。The provided definition does not specif

JenkinsJenkins权威指南英文版:jenkins-the-definitive-guide.pdf

解决:target overrides the `GCC_PREPROCESSOR_DEFINITIONS`

The Definitive C++ Book Guide and List

The service definition selected is invalid

[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the