简体   繁体   中英

update document with _id elasticsearch

I tried to update a document with _id .

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

This is a part of doc.:

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

And here's the request body:

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

But then I get this error:

{
"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

}

How can I update document with _id ?

The URL is not malformed and the request body needs to be valid JSON, like this:

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

The error message clearly saying that you passed the wrong _type name which is _update in your case, as it says in the error message, in short it can't start with _ . change it to something else and it should work.

reason": "Document mapping type name can't start with '_', found: [_update]"

POST http://example.org/testrest/testrest/X3flr2oB9Don9XlKX05E/_update should work , as I noticed in your payload both indexname and type are same.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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