- Painless Scripting Language: other versions:
- Painless Guide
- Painless Language Specification
- Painless contexts
- Context example data
- Runtime fields context
- Ingest processor context
- Update context
- Update by query context
- Reindex context
- Sort context
- Similarity context
- Weight context
- Score context
- Field context
- Filter context
- Minimum should match context
- Metric aggregation initialization context
- Metric aggregation map context
- Metric aggregation combine context
- Metric aggregation reduce context
- Bucket script aggregation context
- Bucket selector aggregation context
- Analysis Predicate Context
- Watcher condition context
- Watcher transform context
- Painless API Reference
- Shared API
- Aggregation Selector API
- Aggs API
- Aggs Combine API
- Aggs Init API
- Aggs Map API
- Aggs Reduce API
- Analysis API
- Bucket Aggregation API
- Field API
- Filter API
- Ingest API
- Interval API
- Moving Function API
- Number Sort API
- Painless Test API
- Processor Conditional API
- Score API
- Script Heuristic API
- Similarity API
- Similarity Weight API
- String Sort API
- Template API
- Terms Set API
- Update API
- Watcher Condition API
- Watcher Transform API
- Xpack Template API
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Update by query context
editUpdate by query context
editUse a Painless script in an update by query operation to add, modify, or delete fields within each of a set of documents collected as the result of query.
Variables
-
params
(Map
, read-only) - User-defined parameters passed in as part of the query.
-
ctx['op']
(String
) - The name of the operation.
-
ctx['_routing']
(String
, read-only) - The value used to select a shard for document storage.
-
ctx['_index']
(String
, read-only) - The name of the index.
-
ctx['_id']
(int
, read-only) - The unique document id.
-
ctx['_version']
(int
, read-only) - The current version of the document.
-
ctx['_source']
(Map
) -
Contains extracted JSON in a
Map
andList
structure for the fields existing in a stored document.
Side Effects
-
ctx['op']
-
Use the default of
index
to update a document. Set tonone
to specify no operation ordelete
to delete the current document from the index. -
ctx['_source']
-
Modify the values in the
Map/List
structure to add, modify, or delete the fields of a document.
Return
-
void
- No expected return value.
API
The standard Painless API is available.
Example
To run this example, first follow the steps in context examples.
The following query finds all seats in a specific section that have not been sold and lowers the price by 2:
POST /seats/_update_by_query { "query": { "bool": { "filter": [ { "range": { "row": { "lte": 3 } } }, { "match": { "sold": false } } ] } }, "script": { "source": "ctx._source.cost -= params.discount", "lang": "painless", "params": { "discount": 2 } } }
Was this helpful?
Thank you for your feedback.