Update a document Beta

POST /{index}/_update/{id}

Updates a document by running a script or passing a partial document.

Path parameters

  • index string Required

    The name of the index

  • id string Required

    Document ID

Query parameters

  • Only perform the operation if the document has this primary term.

  • Only perform the operation if the document has this sequence number.

  • lang string

    The script language.

  • refresh string

    If 'true', Elasticsearch refreshes the affected shards to make this operation visible to search, if 'wait_for' then wait for a refresh to make this operation visible to search, if 'false' do nothing with refreshes.

    Values are true, false, or wait_for.

  • If true, the destination must be an index alias.

  • Specify how many times should the operation be retried when a conflict occurs.

  • routing string

    Custom value used to route operations to a specific shard.

  • timeout string

    Period to wait for dynamic mapping updates and active shards. This guarantees Elasticsearch waits for at least the timeout before failing. The actual wait time could be longer, particularly when multiple waits occur.

  • wait_for_active_shards number | string

    The number of shard copies that must be active before proceeding with the operations. Set to 'all' or any positive integer up to the total number of shards in the index (number_of_replicas+1). Defaults to 1 meaning the primary shard.

  • _source boolean | string | array[string]

    Set to false to disable source retrieval. You can also specify a comma-separated list of the fields you want to retrieve.

  • _source_excludes string | array[string]

    Specify the source fields you want to exclude.

  • _source_includes string | array[string]

    Specify the source fields you want to retrieve.

application/json

Body Required

  • Set to false to disable setting 'result' in the response to 'noop' if no change to the document occurred.

  • doc object

    A partial update to an existing document.

    Additional properties are allowed.

  • Set to true to use the contents of 'doc' as the value of 'upsert'

  • script object

    Additional properties are allowed.

    Hide script attributes Show script attributes object
    • source string

      The script source.

    • id string
    • params object

      Specifies any named parameters that are passed into the script as variables. Use parameters instead of hard-coded values to decrease compile time.

      Hide params attribute Show params attribute object
      • * object Additional properties

        Additional properties are allowed.

    • lang string

      Any of:

      Values are painless, expression, mustache, or java.

    • options object
      Hide options attribute Show options attribute object
      • * string Additional properties
  • Set to true to execute the script whether or not the document exists.

  • _source boolean | object

    Defines how to fetch a source. Fetching can be disabled entirely, or the source can be filtered.

    One of:
  • 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 executed.

    Additional properties are allowed.

Responses

POST /{index}/_update/{id}
curl \
 -X POST http://api.example.com/{index}/_update/{id} \
 -H "Content-Type: application/json" \
 -d '{"detect_noop":true,"doc":{},"doc_as_upsert":true,"script":{"source":"string","id":"string","params":{"additionalProperty1":{},"additionalProperty2":{}},"":"painless","options":{"additionalProperty1":"string","additionalProperty2":"string"}},"scripted_upsert":true,"":true,"upsert":{}}'