Skip to content

Commit 989bad1

Browse files
committed
Upsert documentation clarification
1 parent da8617e commit 989bad1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

specification/_global/update/UpdateRequest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ export interface Request<TDocument, TPartialDocument> extends RequestBase {
180180
*/
181181
_source?: SourceConfig
182182
/**
183+
* Upserts are powerful operations that enable you to perform both update and insert actions in a single request.
183184
* If the document does not already exist, the contents of 'upsert' are inserted as a new document.
184-
* If the document exists, the 'script' is run.
185+
* If the document exists, the script is run.
185186
* @prop_serializer SourceFormatter`1
186187
*/
187188
upsert?: TDocument
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
summary: Upsert
22
# method_request: POST test/_update/1
33
description: >
4-
Run `POST test/_update/1` to perfom an upsert.
5-
If the document does not already exist, the contents of the upsert element are inserted as a new document. If the document exists, the script is run.
4+
Run `POST test/_update/1` to perfom update and insert actions in a single request.
5+
In this example, if the product with ID 1 exists, its price will be updated to 100.
6+
If the product does not exist, a new document with ID 1 and a price of 50 will be inserted.
67
# type: request
78
value:
8-
"{\n \"script\": {\n \"source\": \"ctx._source.counter += params.count\"\
9-
,\n \"lang\": \"painless\",\n \"params\": {\n \"count\": 4\n }\n \
10-
\ },\n \"upsert\": {\n \"counter\": 1\n }\n}"
9+
{
10+
"doc": {
11+
"product_price": 100
12+
},
13+
"upsert": {
14+
"product_price": 50
15+
}
16+
}

0 commit comments

Comments
 (0)