首页 > 解决方案 > 在弹性搜索的索引下为文档类型创建映射时出错

问题描述

您好我正在尝试使用 kibana 控制台在弹性搜索中的索引“电子商务”下创建文档类型“产品”。

PUT /ecommerce
{
  "mappings": {
    "product": {
      "properties": {
        "name": {
          "type": "string"
        },
        "price": {
          "type": "double"
        },
        "description": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "quantity": {
          "type": "integer"
        },
        "categories": {
          "type": "nested",
          "properties": {
            "name": {
              "type": "string"
            }
          }
        },
        "tags": {
          "type": "string"
        }
      }
    }
  }
}

当我运行此请求时,我收到以下错误

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [product : {properties={quantity={type=integer}, price={type=double}, name={type=string}, description={type=string}, categories={type=nested, properties={name={type=string}}}, status={type=string}, tags={type=string}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [product : {properties={quantity={type=integer}, price={type=double}, name={type=string}, description={type=string}, categories={type=nested, properties={name={type=string}}}, status={type=string}, tags={type=string}}}]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters:  [product : {properties={quantity={type=integer}, price={type=double}, name={type=string}, description={type=string}, categories={type=nested, properties={name={type=string}}}, status={type=string}, tags={type=string}}}]"
    }
  },
  "status": 400
}

知道我的 put 请求有什么问题。多谢

标签: elasticsearchlucene

解决方案


您不能在 ES 7.0 版中创建类型并且它已被弃用。您可以从此链接获得以下可用信息

不推荐在请求中指定类型。例如,索引文档不再需要文档类型。新的索引 API 是 PUT {index}/_doc/{id} 用于显式 ID 和 POST {index}/_doc 用于自动生成的 ID。请注意,在 7.0 中,_doc 是路径的永久部分,表示端点名称而不是文档类型。

我建议遵循此处提到的任何方法

基本上要么为每个文档类型创建一个新索引,要么只添加一个新的自定义类型字段。

以下是您的映射方式:

POST <your_new_index_name>
{  
   "mappings":{  
      "properties":{  
         "name":{  
            "type":"string"
         },
         "price":{  
            "type":"double"
         },
         "description":{  
            "type":"string"
         },
         "status":{  
            "type":"string"
         },
         "quantity":{  
            "type":"integer"
         },
         "categories":{  
            "type":"nested",
            "properties":{  
               "name":{  
                  "type":"string"
               }
            }
         },
         "tags":{  
            "type":"string"
         }
      }
   }
}

基本上,如果您尝试摄取任何新文档,则必须使用以下端点:

PUT <your_new_index_name>/_doc/1
{
  "myfield":"myvalue"
}

希望这可以帮助!


推荐阅读