Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch update with scripts : what does ctx mean?

curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
  "script" : "ctx._source.age += 5"
}'

This an example on official site. I am confused with ctx, what does it mean? Context?

like image 336
马慧超 Avatar asked Jun 08 '16 07:06

马慧超


People also ask

What is CTX in Kibana?

the ctx. payload field contains the response of the search request you executed in your input. If you execute a HTTP request against any service, this payload will change according to the response.

What is CTX in painless?

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. ctx['_source'] Modify the values in the Map/List structure to add, modify, or delete the fields of a document.

Can you update a document in Elasticsearch?

DescriptioneditEnables you to script document updates. The script can update, delete, or skip modifying the document. The update API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API.

What is painless script in Elasticsearch?

Painless is a simple, secure scripting language designed specifically for use with Elasticsearch. It is the default scripting language for Elasticsearch and can safely be used for inline and stored scripts.


1 Answers

ctx is a special variable that allows you to access the source of the object that you want to update. The ctx._source is a writable version of the source.

NOTE: You can modify this document in the script and the modified source will be persisted as the new version of the document.

like image 73
td4u Avatar answered Sep 30 '22 16:09

td4u