﻿---
title: Update context
description: Use a Painless script in an update operation to add, modify, or delete fields within a single document. Variables Side Effects Return API The standard...
url: https://www.elastic.co/elastic/docs-builder/docs/2439/reference/scripting-languages/painless/painless-update-context
products:
  - Painless
---

# Update context
Use a Painless script in an [update](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update) operation to add, modify, or delete fields within a single document.
**Variables**
<definitions>
  <definition term="params (Map, read-only)">
    User-defined parameters passed in as part of the query.
  </definition>
  <definition term="ctx['op'] (String)">
    The name of the operation.
  </definition>
  <definition term="ctx['_routing'] (String, read-only)">
    The value used to select a shard for document storage.
  </definition>
  <definition term="ctx['_index'] (String, read-only)">
    The name of the index.
  </definition>
  <definition term="ctx['_id'] (String, read-only)">
    The unique document id.
  </definition>
  <definition term="ctx['_version'] (int, read-only)">
    The current version of the document.
  </definition>
  <definition term="ctx['_now'] (long, read-only)">
    The current timestamp in milliseconds.
  </definition>
  <definition term="ctx['_source'] (Map)">
    Contains extracted JSON in a `Map` and `List` structure for the fields existing in a stored document.
  </definition>
</definitions>

**Side Effects**
<definitions>
  <definition term="ctx['op']">
    Use the default of `index` to update a document. Set to `none` to specify no operation or `delete` to delete the current document from the index.
  </definition>
  <definition term="ctx['_source']">
    Modify the values in the `Map/List` structure to add, modify, or delete the fields of a document.
  </definition>
</definitions>

**Return**
<definitions>
  <definition term="void">
    No expected return value.
  </definition>
</definitions>

**API**
The standard [Painless API](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared.html) is available.
**Example**
To run this example, first follow the steps in [context examples](https://www.elastic.co/elastic/docs-builder/docs/2439/reference/scripting-languages/painless/painless-context-examples).
The following query updates a document to be sold, and sets the cost to the actual price paid after discounts:
```json

{
  "script": {
    "source": "ctx._source.sold = true; ctx._source.cost = params.sold_cost",
    "lang": "painless",
    "params": {
      "sold_cost": 26
    }
  }
}
```