繁体   English   中英

无法解析 _doc 类型:Elasticsearch 7.x 中的映射错误

[英]Failed to parse _doc type: Mapping errors in Elasticsearch 7.x

尝试使用以下查询在 elasticsearch 中创建索引

PUT company
{
  "mappings": {
    "employees": {
      "properties": {
        "id": {
          "type": "long"
        },
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "birth": {
          "type": "date"
        },
        "addr": {
          "type": "text"
        }
      }
    }
  },
  "settings": {
    "index": {
      "number_of_shards": "5",
      "number_of_replicas": "1"
    }
  }
}

在 Kibana 仪表板中执行查询后出现以下错误我认为有关天气的问题我给出了一些错误的参数:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [employees : {properties={name={type=text, fields={keyword={ignore_above=256, type=keyword}}}, birth={type=date}, id={type=long}, addr={type=text}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [employees : {properties={name={type=text, fields={keyword={ignore_above=256, type=keyword}}}, birth={type=date}, id={type=long}, addr={type=text}}}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [employees : {properties={name={type=text, fields={keyword={ignore_above=256, type=keyword}}}, birth={type=date}, id={type=long}, addr={type=text}}}]"
    }
  },
  "status" : 400
}

这是因为 ES >= 7.0 删除了对映射类型的支持,所以您可以尝试使用自定义类型_doc而不是employee类型。 查看更多: https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

PUT company
{
"mappings": {
"_doc": {
  "properties": {
    "id": {
      "type": "long"
    },
    "name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "birth": {
      "type": "date"
    },
    "addr": {
      "type": "text"
    }
  }
 }
},
"settings": {
 "index": {
  "number_of_shards": "5",
  "number_of_replicas": "1"
  }
 }
}

根据这份文件:

https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

Elasticsearch 版本 7.x 已弃用映射类型。 您也可以在不提及_doc的情况下放置您的映射。

PUT company
{
  "mappings": {
    "properties": {
      "id": {
        "type": "long"
      },
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "birth": {
        "type": "date"
      },
      "addr": {
        "type": "text"
      }
    }
  },
  "settings": {
     "index": {
         "number_of_shards": "5",
         "number_of_replicas": "1"
     }
  }
}

Output:

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "company"
}

核实:

GET company/_mapping

Output:

{
  "company" : {
    "mappings" : {
      "properties" : {
        "addr" : {
          "type" : "text"
        },
        "birth" : {
          "type" : "date"
        },
        "id" : {
          "type" : "long"
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

我希望这会有所帮助,更容易理解,并避免围绕_doc属性产生混淆。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM