elasticsearch - 在弹性搜索的索引下为文档类型创建映射时出错
问题描述
您好我正在尝试使用 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 请求有什么问题。多谢
解决方案
您不能在 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"
}
希望这可以帮助!
推荐阅读
- json - 如何在 Swift 中从 JSON 返回集合视图 numberOfItemsInSection 中的 Max 10 个项目
- qt - QtWebEngineProcess 启动后立即关闭
- react-native - 构建 JavaScript 包失败。node_modules\expo\AppEntry.js:Transformer.transform 不是函数
- .net - 我需要在模拟单 CPU 机器的 Visual Studio 2019 中调试 WinForms 应用程序
- airflow - 运行中的气流 dag 问题 - 循环运行计划
- javascript - $_POST 仅包含部分提交的数据
- javascript - React Native Firebase 多张图片上传问题
- python - 如果用户按下“q”,如何立即中断 while 循环
- mongodb - 如何在 Retool 上从 MongoDB 插入许多?
- send - Lora 双工通信