# Update a document **POST /{index}/_update/{id}** Update a document by running a script or passing a partial document. If the Elasticsearch security features are enabled, you must have the `index` or `write` index privilege for the target index or index alias. The script can update, delete, or skip modifying the document. The API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API. This operation: * Gets the document (collocated with the shard) from the index. * Runs the specified script. * Indexes the result. The document must still be reindexed, but using this API removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation. The `_source` field must be enabled to use this API. In addition to `_source`, you can access the following variables through the `ctx` map: `_index`, `_type`, `_id`, `_version`, `_routing`, and `_now` (the current timestamp). For usage examples such as partial updates, upserts, and scripted updates, see the External documentation. ## Required authorization * Index privileges: `write` [External documentation](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/update-document) ## Servers - http://api.example.com: http://api.example.com () ## Authentication methods - Api key auth - Basic auth - Bearer auth ## Parameters #### Path parameters - **index** (string) The name of the target index. By default, the index is created automatically if it doesn't exist. - **id** (string) A unique identifier for the document to be updated. #### Query parameters - **if_primary_term** (number) Only perform the operation if the document has this primary term. - **if_seq_no** (number) Only perform the operation if the document has this sequence number. - **include_source_on_error** (boolean) True or false if to include the document source in the error message in case of parsing errors. - **lang** (string) The script language. - **refresh** (string) If 'true', Elasticsearch refreshes the affected shards to make this operation visible to search. If 'wait_for', it waits for a refresh to make this operation visible to search. If 'false', it does nothing with refreshes. - **require_alias** (boolean) If `true`, the destination must be an index alias. - **retry_on_conflict** (number) The number of times the operation should be retried when a conflict occurs. - **routing** (string) A custom value used to route operations to a specific shard. - **timeout** (string) The period to wait for the following operations: dynamic mapping updates and waiting for active shards. Elasticsearch waits for at least the timeout period before failing. The actual wait time could be longer, particularly when multiple waits occur. - **wait_for_active_shards** (number | string) The number of copies of each shard that must be active before proceeding with the operation. Set to 'all' or any positive integer up to the total number of shards in the index (`number_of_replicas`+1). The default value of `1` means it waits for each primary shard to be active. - **_source** (boolean | string | array[string]) If `false`, source retrieval is turned off. You can also specify a comma-separated list of the fields you want to retrieve. - **_source_excludes** (string | array[string]) The source fields you want to exclude. - **_source_includes** (string | array[string]) The source fields you want to retrieve. ## Body parameters Content-type: application/json - **detect_noop** (boolean) If `true`, the `result` in the response is set to `noop` (no operation) when there are no changes to the document. - **doc** (object) A partial update to an existing document. If both `doc` and `script` are specified, `doc` is ignored. - **doc_as_upsert** (boolean) If `true`, use the contents of 'doc' as the value of 'upsert'. NOTE: Using ingest pipelines with `doc_as_upsert` is not supported. - **script** (object) The script to run to update the document. - **scripted_upsert** (boolean) If `true`, run the script whether or not the document exists. - **_source** (boolean | object) If `false`, turn off source retrieval. You can also specify a comma-separated list of the fields you want to retrieve. - **upsert** (object) 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. ## Responses ### 200: #### Body Parameters: application/json (object) - **_id** (string) The unique identifier for the added document. - **_index** (string) The name of the index the document was added to. - **_primary_term** (number) The primary term assigned to the document for the indexing operation. - **result** (string) The result of the indexing operation: `created` or `updated`. - **_seq_no** (number) The sequence number assigned to the document for the indexing operation. Sequence numbers are used to ensure an older version of a document doesn't overwrite a newer version. - **_shards** (object) Information about the replication process of the operation. - **_version** (number) The document version, which is incremented each time the document is updated. - **failure_store** (string) The role of the failure store in this document response - **forced_refresh** (boolean) - **get** (object) [Powered by Bump.sh](https://bump.sh)