# Painless Reindex Script saving long as integer

**URL:** https://discuss.elastic.co/t/painless-reindex-script-saving-long-as-integer/273445
**Category:** Elasticsearch
**Tags:** painless
**Created:** [May 19, 2021, 9:05pm UTC](https://discuss.elastic.co/t/painless-reindex-script-saving-long-as-integer/273445 "2021-05-19T21:05:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)
#### Post date: [May 19, 2021, 9:05pm UTC](https://discuss.elastic.co/t/painless-reindex-script-saving-long-as-integer/273445/1 "2021-05-19T21:05:59Z")

</div>

Hi all,

I am trying to use a painless script as part of a reindex to multiply a long by a number, and then save it as the source field. However, when the new value is saved it is saved as an integer instead of a long resulting in an overflow, and thus a messed up number. Does anyone have any ideas on this? I wasn't able to find much on Google about this issue.

Here is an example mapping:

```json
{
  "properties": {
    "telephony": {
      "properties": {
        "duration": {
          "type": "long"
        }
      }
    }
  }
}

```

Here is an example input doc:

```json
{
  "telephony.duration": 48
}

```

Here is the script that is being run:

```auto
if (ctx._source.telephony.duration != null && ctx._source.telephony.duration > 0) { long duration = ctx._source.telephony.duration*1000000000; ctx._source.telephony.duration = (long)duration; }

```

Here is the output that I get:

```auto
{
  "telephony.duration": 755359744
}

```

Clearly the output has been added as an integer rather than a long, as the output number isn't even possible if it were executing the math correctly. What I don't understand is how/why this is happening, as everything that I can see should result in a long output.

---

<div class="post-metadata">

### Author: ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)
#### Post date: [May 20, 2021, 12:44pm UTC](https://discuss.elastic.co/t/painless-reindex-script-saving-long-as-integer/273445/2 "2021-05-20T12:44:12Z")

</div>

I was able to figure this out. I needed to add `(long)` to the multiplication part so that it would be treaty as a long from the start.

The working script is:

```auto
if (ctx._source.telephony.duration != null && ctx._source.telephony.duration > 0) { long duration = (long)ctx._source.telephony.duration*1000000000; ctx._source.telephony.duration = (long)duration; }

```

---

<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: [June 17, 2021, 12:45pm UTC](https://discuss.elastic.co/t/painless-reindex-script-saving-long-as-integer/273445/3 "2021-06-17T12:45:01Z")

</div>

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