Update with calculation

Hi,

We have just discovered a bug in our system which made a wrong calculation.

Fortunately for us, all documents contain enough data to reprocess the calculation.

My question

How can I run an "update" so that it recomputes a field, based on the content of other fields ?

Example:
{
"amount": 5,
"unit_price": 25.2,
"total_price": 30.2 (wrong value, based on erroneous calculations)
}
I would like to replace the "total_price" by the result of "amount" * "unit_price" in all documents (~500000000)

Many thanks for your help

Have a look at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html

You can execute a script as explained in this doc.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.