Update field vaule with base64 encode

Hello Team,

I got a requirement that have to query and update some fields value with base64 code for all documents.

can we change the field value to base64 by using _update_by_query API.

Ex:

POST test/_doc
{
    "foo": "bar",
    "bar": "foo",
    "account": "123456789"
}

POST test/_update_by_query?wait_for_completion=true&conflicts=proceed
{
  "script": "ctx._source.remove('account')=base64('account')",
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "account"
          }
        }
      ]
    }
  }
}

Expected result
POST test/_doc
{
    "foo": "bar",
    "bar": "foo",
    "account": "MTIzNDU2Nzg5Cg=="
}

Regards
Kannan P

See - [Painless: Add augmentation to String for base 64 by nik9000 · Pull Request #22665 · elastic/elasticsearch · GitHub](PR 22665)

This should get you what you are looking for:

  "script": "ctx._source['account'] = ctx._source['account'].encodeBase64()",

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