【问题标题】:update document with _id elasticsearch使用 _id elasticsearch 更新文档
【发布时间】:2019-05-14 13:56:08
【问题描述】:

我尝试使用_id 更新文档。

POST http://example.org/testrest/_update/X3flr2oB9Don9XlKX05E

这是文档的一部分:

"hits": [
        {
            "_index": "testrest",
            "_type": "testrest",
            "_id": "X3flr2oB9Don9XlKX05E",
            "_score": 0,
            "_source": {
                "price_diff_per_sys": "199.8999",
                "specs": "",
                "gtin_match": "0",
                "human_verdict": "Awaiting",

这是请求正文:

{
  "doc": { 
    "human_verdict": "Match"
  }
}

然后我得到这个错误:

{
"error": {
    "root_cause": [
        {
            "type": "invalid_type_name_exception",
            "reason": "Document mapping type name can't start with '_', found: [_update]"
        }
    ],
    "type": "invalid_type_name_exception",
    "reason": "Document mapping type name can't start with '_', found: [_update]"
},
"status": 400

}

如何使用_id 更新文档?

【问题讨论】:

  • 你使用的是哪个版本

标签: elasticsearch


【解决方案1】:

URL 格式正确,请求正文需要是有效的 JSON,如下所示:

POST http://example.org/testrest/testrest/X3flr2oB9Don9XlKX05E/_update
{
  "doc": { 
    "human_verdict": "Match"
  }
}

【讨论】:

    【解决方案2】:

    错误消息清楚地表明您传递了错误的_type 名称,在您的情况下是_update,正如错误消息中所说,简而言之,它不能以_ 开头。将其更改为其他内容,它应该可以工作。

    reason": "文档映射类型名称不能以'_'开头,发现: [_update]"

    POST http://example.org/testrest/testrest/X3flr2oB9Don9XlKX05E/_update 应该可以工作,正如我在您的有效负载中注意到的那样,索引名称和类型都相同。

    "_index": "testrest",
     "_type": "testrest",
    

    【讨论】:

    • 他仍然需要点击 URL 末尾的 _update 端点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    相关资源
    最近更新 更多