Replace a document #
Replace an existing document by specifying its unique identifier and the new content.
Examples #
Replace a document news_001 of the collection my-collection with new content:
PUT /my-collection/_doc/news_001
{
"message": "GET /search HTTP/1.1 200 1070000",
"org": {
"id": "infinilabs"
}
}
The API returns as following result:
{"_id":"0,0", "_key":"news_001", "result":"updated"}
After the document modification, If you perform the fetch request:
GET /my-collection/_doc/news_001
It returns an updated document like:
{
"_collection": "default:my-collection",
"_id": "0,0",
"_key" : "news_001",
"found": true,
"source" : {
"message": "GET /search HTTP/1.1 200 1070000",
"org": {
"id": "infinilabs"
}
}
}
The replacement happens in place: the document keeps its original _id, and the
index entries of the old version are rebuilt under the same _id. Since this is
a full replacement, fields that are omitted from the request body are cleared.
The _id in the response is always the identifier the document actually lives
under. Re-creating a document with the key of a previously deleted document
reuses that document’s original _id as well, because key mappings survive
deletion.
Request #
PUT /<target>/_doc/<doc_id>
{<fields>}
Path parameters #
<target>
(Required, string) Name of the collection to target.<doc_id>
(Required, string) The unique identify of this document, support both_keyor_id.
Request body #
<fields>
(Required, string) Request body contains the JSON source for the document data.