From d417b5d85a0bcd293ec33af983992ee6123d250b Mon Sep 17 00:00:00 2001 From: Alek Poteet <26228118+apoteet@users.noreply.github.com> Date: Tue, 23 Aug 2022 19:58:03 -0600 Subject: [PATCH] Add examples for bulk script & upsert updates (#783) There is no mention of doc_as_upsert in OS documention, but it appears to be supported. Some examples to go along with the passing mention of scripts & especially upsert would go a long way This also addresses #755 Signed-off-by: Alek Poteet Signed-off-by: Alek Poteet --- _opensearch/rest-api/document-apis/bulk.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/_opensearch/rest-api/document-apis/bulk.md b/_opensearch/rest-api/document-apis/bulk.md index ea84e106..6f6d90f4 100644 --- a/_opensearch/rest-api/document-apis/bulk.md +++ b/_opensearch/rest-api/document-apis/bulk.md @@ -103,13 +103,26 @@ All actions support the same metadata: `_index`, `_id`, and `_require_alias`. If - Update - This action updates existing documents and returns an error if the document doesn't exist. The next line must include a full or partial JSON document, depending on how much of the document you want to update. It can also include a script or upsert for more complex document updates. + This action updates existing documents and returns an error if the document doesn't exist. The next line must include a full or partial JSON document, depending on how much of the document you want to update. ```json { "update": { "_index": "movies", "_id": "tt0816711" } } { "doc" : { "title": "World War Z" } } ``` + + It can also include a script or upsert for more complex document updates. + - Script + ```json + { "update": { "_index": "movies", "_id": "tt0816711" } } + { "script" : { "source": "ctx._source.title = \"World War Z\"" } } + ``` + + - Upsert + ```json + { "update": { "_index": "movies", "_id": "tt0816711" } } + { "doc" : { "title": "World War Z" }, "doc_as_upsert": true } + ``` ## Response