Root mapping definition has unsupported parameters

使用ElasticSearch创建映射报错

Root mapping definition has unsupported parameters

原因

使用的ES版本为7.2.0,不再支持创建指定类型,索引的默认类型为_doc.
官网图片

解决办法

创建索引的映射时,不需要指定类型即可

错误再现

错误的创建索引语句

PUT /dangdang1
{
  "mappings": {
    "book":{  # 这里指定了类型type
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "keyword"
        },
        "price": {
          "type": "double"
        },
        "detail": {
          "type": "text"
        }
      }
    }
  }
}

报错信息

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [book : {properties={price={type=double}, name={type=keyword}, id={type=integer}, detail={type=text}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [book : {properties={price={type=double}, name={type=keyword}, id={type=integer}, detail={type=text}}}]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters:  [book : {properties={price={type=double}, name={type=keyword}, id={type=integer}, detail={type=text}}}]"
    }
  },
  "status": 400
}

正确的创建索引映射的语句

PUT /dangdang
{
  "mappings": {
      # 这里不再写类型
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "keyword"
        },
        "price": {
          "type": "double"
        },
        "detail": {
          "type": "text"
        }
      }
  }
}
posted @ 2020-11-25 00:16  juyss  阅读(7229)  评论(0编辑  收藏  举报