# Copy String field to new Integer Field gives error

**URL:** <https://discuss.elastic.co/t/copy-string-field-to-new-integer-field-gives-error/290590>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [November 30, 2021, 6:31pm UTC](https://discuss.elastic.co/t/copy-string-field-to-new-integer-field-gives-error/290590 "2021-11-30T18:31:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Mightiev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_mightiev/32/62186_2.png) [@A\_Mightiev](https://discuss.elastic.co/u/A_Mightiev)\
**Post date:** [November 30, 2021, 6:31pm UTC](https://discuss.elastic.co/t/copy-string-field-to-new-integer-field-gives-error/290590/1 "2021-11-30T18:31:07Z")

</div>

Hello  
I have a keyword field that it should be a numeric instead. To avoid reindexing all my data I created a new field with the right numeric mapping. I would like to add the old data to the new mapping  
I am trying this

```auto
POST index-00004/_update_by_query
{
  "script": {
    "source": "ctx._source['log.numeric.duration']=ctx._source['log.values.duration']",
    "lang": "painless"
  }, 
  "query": {
    "exists": {
      "field": "log.values.duration"
    }
  }
}

```

The problem is I get this error

```auto
  "failures" : [
    {
      "index" : "index-00004",
      "type" : "_doc",
      "id" : "IaoKMnwB10PZ-PXKMS01",
      "cause" : {
        "type" : "version_conflict_engine_exception",
        "reason" : "[IaoKMnwB10PZ-PXKMS01]: version conflict, required seqNo [739121], primary term [1]. current document has seqNo [10651181] and primary term [1]",
        "index_uuid" : "fPuIF4R1SmGR03MtHG3V0A",
        "shard" : "1",
        "index" : "index-00004"
      },
      "status" : 409
    },

```

I thought I would parse the string to int but it gives me another error

```auto
  "script": {
    "source": "ctx._source['log.values.duration']=Integer.parseInt(ctx._source['log.coflowco.num.duration'].value)",

```

It gives error:

```auto
        "script_stack" : [
          "ctx._source['log.values.duration']=Integer.parseInt(ctx._source['log.numeric.duration'].value)",
          " ^---- HERE"

```

Any other ideas??

---

<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:** [December 28, 2021, 6:31pm UTC](https://discuss.elastic.co/t/copy-string-field-to-new-integer-field-gives-error/290590/2 "2021-12-28T18:31:11Z")

</div>

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