[DOCS] Upsert documentation clarification (#120684)

Co-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>
This commit is contained in:
Kofi B 2025-01-29 03:46:01 -05:00 committed by GitHub
parent 8185cafaf2
commit 63a890e30d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 11 deletions

View File

@ -307,23 +307,19 @@ POST test/_update/1
[discrete]
===== Upsert
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 executed:
An upsert operation lets you update an existing document or insert a new one if it doesn't exist, in a single request.
In this example, if the product with ID `1` exists, its price will be updated to `100`. If the product does not exist, a new document with ID `1` and a price of `50` will be inserted.
[source,console]
----
POST test/_update/1
POST /test/_update/1
{
"script": {
"source": "ctx._source.counter += params.count",
"lang": "painless",
"params": {
"count": 4
}
"doc": {
"product_price": 100
},
"upsert": {
"counter": 1
"product_price": 50
}
}
----