# Copy field and convert to lowercase

**URL:** <https://discuss.elastic.co/t/copy-field-and-convert-to-lowercase/136301>\
**Category:** Elasticsearch\
**Created:** [June 18, 2018, 11:48am UTC](https://discuss.elastic.co/t/copy-field-and-convert-to-lowercase/136301 "2018-06-18T11:48:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atom/32/34758_2.png) [@atom](https://discuss.elastic.co/u/atom)\
**Post date:** [June 18, 2018, 11:48am UTC](https://discuss.elastic.co/t/copy-field-and-convert-to-lowercase/136301/1 "2018-06-18T11:48:24Z")

</div>

Hi There,  
in all of my indices i have a field that i want to copy to a new field and convert it to lowercase.

Copying was easy:

```
    POST /INDEX-2018.06.07/_update_by_query?conflicts=proceed&refresh=true
{
    "query" : {
        "match_all" : {}
    },
    "script" : "ctx._source.fieldB_norm = ctx._source.fieldA;"
}

```

Unfortunately, converting to lowercase didn't worked.

I did in a second step:

```
POST /INDEX-2018.06.07/_update_by_query?conflicts=proceed&refresh=true
{
    "query" : {
        "match_all" : {}
    },
    "script" : "ctx._source.fieldB = ctx._source.fieldB.toLowerCase();"
}

```

And got this error message:

```
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "ctx._source.jv_keyword_search_norm = ctx._source.fieldB.toLowerCase();",
          " ^---- HERE"
        ],
        "script": "ctx._source.fieldB_norm = ctx._source.fieldB.toLowerCase();",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "ctx._source.fieldB_norm = ctx._source.fieldB.toLowerCase();",
      " ^---- HERE"
    ],
    "script": "ctx._source.fieldB_norm = ctx._source.fieldB.toLowerCase();",
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 500
}

```

Any Ideas how to do this?  
I would be happy if i dont need to reindex everything 🙂

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atom/32/34758_2.png) [@atom](https://discuss.elastic.co/u/atom)\
**Post date:** [June 20, 2018, 1:47pm UTC](https://discuss.elastic.co/t/copy-field-and-convert-to-lowercase/136301/2 "2018-06-20T13:47:02Z")

</div>

I've been able to solve this by myself with updating each entry manually using a php script 🙂  
close pls

---

<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:** [July 18, 2018, 1:47pm UTC](https://discuss.elastic.co/t/copy-field-and-convert-to-lowercase/136301/3 "2018-07-18T13:47:12Z")

</div>

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