Skip to content

[DOCS] Upsert documentation clarification #3591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion output/openapi/elasticsearch-openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion output/openapi/elasticsearch-serverless-openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions output/schema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion specification/_global/update/UpdateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ export interface Request<TDocument, TPartialDocument> extends RequestBase {
*/
_source?: SourceConfig
/**
* Upserts are powerful operations that enable you to perform both update and insert actions in a single request.
* If the document does not already exist, the contents of 'upsert' are inserted as a new document.
* If the document exists, the 'script' is run.
* If the document exists, the script is run.
* @prop_serializer SourceFormatter`1
*/
upsert?: TDocument
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
summary: Upsert
# method_request: POST test/_update/1
description: >
Run `POST test/_update/1` to perfom an 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 run.
Run `POST test/_update/1` to perfom update and insert actions 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.
# type: request
value:
"{\n \"script\": {\n \"source\": \"ctx._source.counter += params.count\"\
,\n \"lang\": \"painless\",\n \"params\": {\n \"count\": 4\n }\n \
\ },\n \"upsert\": {\n \"counter\": 1\n }\n}"
value: { 'doc': { 'product_price': 100 }, 'upsert': { 'product_price': 50 } }
Loading