# Update field vaule with base64 encode

**URL:** <https://discuss.elastic.co/t/update-field-vaule-with-base64-encode/292117>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 16, 2021, 9:12am UTC](https://discuss.elastic.co/t/update-field-vaule-with-base64-encode/292117 "2021-12-16T09:12:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kannan\_raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kannan_raj/32/63201_2.png) [@kannan\_raj](https://discuss.elastic.co/u/kannan_raj)\
**Post date:** [December 16, 2021, 9:12am UTC](https://discuss.elastic.co/t/update-field-vaule-with-base64-encode/292117/1 "2021-12-16T09:12:17Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![angelo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/angelo/32/61325_2.png) [@angelo](https://discuss.elastic.co/u/angelo)\
**Post date:** [December 20, 2021, 7:53pm UTC](https://discuss.elastic.co/t/update-field-vaule-with-base64-encode/292117/2 "2021-12-20T19:53:00Z")

</div>

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

This should get you what you are looking for:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 17, 2022, 7:53pm UTC](https://discuss.elastic.co/t/update-field-vaule-with-base64-encode/292117/3 "2022-01-17T19:53:20Z")

</div>

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