首页 > 解决方案 > 如果映射类型已被删除,为什么我必须将新文档放入嵌套 URI?

问题描述

我在 Elasticsearch 7.14.0 上,其中映射类型已被删除

如果我运行以下命令:

curl -X PUT "localhost:9200/products/1?pretty" -H 'Content-Type: application/json' -d'
{
    "name": "Toast"
}
'

我明白了

{
  "error" : "Incorrect HTTP method for uri [/products/1?pretty] and method [PUT], allowed: [POST]",
  "status" : 405
}

似乎弹性希望我PUT/index/type/URI 中使用它:

curl -X PUT "localhost:9200/pop/products/1?pretty" -H 'Content-Type: application/json' -d'
{
    "name": "Toast"
}
'
{
  "_index" : "pop",
  "_type" : "products",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

我想知道如果映射类型已被删除,为什么我必须有一个指示类型的嵌套 URI?

标签: elasticsearch

解决方案


您必须添加_doc到您的 put 请求调用,如下所示

curl -X PUT "localhost:9200/products/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
    "name": "Toast"
}
'

elasticsearch官方文档中提到,在7.x中删除映射类型后,您需要_doc为文档索引,获取和删除API添加,(不代表文档类型,而是代表端点名称)


推荐阅读