# Reindex scripting help?

**URL:** <https://discuss.elastic.co/t/reindex-scripting-help/57046>\
**Category:** Elasticsearch\
**Created:** [August 2, 2016, 7:02pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046 "2016-08-02T19:02:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Suh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_suh/32/10638_2.png) [@Steve\_Suh](https://discuss.elastic.co/u/Steve_Suh)\
**Post date:** [August 2, 2016, 7:02pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046/1 "2016-08-02T19:02:02Z")

</div>

Here's my script:

```auto
POST /_reindex
{
  size: 1,
  "source": {
    "index": "roots_index0"
  },
  "dest": {
    "index": "roots_index2"
  },
  "script" : { "inline": "ctx._source.id = rint(ctx._id)"}
}

```

I'm trying to store a numeric version of \_id as id. I get the following error:

```auto
{
   "error": {
      "root_cause": [
         {
            "type": "script_exception",
            "reason": "failed to run inline script [ctx._source.id = rint(ctx._id)] using lang [groovy]"
         }
      ],
      "type": "script_exception",
      "reason": "failed to run inline script [ctx._source.id = rint(ctx._id)] using lang [groovy]",
      "caused_by": {
         "type": "missing_method_exception",
         "reason": "No signature of method: static java.lang.Math.rint() is applicable for argument types: (java.lang.String) values: [42361342]\nPossible solutions: rint(double), print(java.io.PrintWriter), print(java.lang.Object), find(), sin(double), sinh(double)"
      }
   },
   "status": 500
}

```

Is there not a way to convert a string to a number? [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html)

---

<div class="post-metadata">

**Author:** ![Steve\_Suh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_suh/32/10638_2.png) [@Steve\_Suh](https://discuss.elastic.co/u/Steve_Suh)\
**Post date:** [August 2, 2016, 7:15pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046/2 "2016-08-02T19:15:23Z")

</div>

Looks like I can run any built in Groovy call. 🙂

---

<div class="post-metadata">

**Author:** ![Steve\_Suh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steve_suh/32/10638_2.png) [@Steve\_Suh](https://discuss.elastic.co/u/Steve_Suh)\
**Post date:** [August 2, 2016, 7:16pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046/3 "2016-08-02T19:16:42Z")

</div>

On a different note, is there a way to have the reindexing call pull in values outside of the document? I'm currently bulk indexing to rebuild my indices but I was wondering if I could reuse reindex instead to add new fields and values from outside the document.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [August 2, 2016, 7:25pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046/4 "2016-08-02T19:25:25Z")

</div>

> [@Steve\_Suh](#):
>
> Looks like I can run any built in Groovy call.

Right, `ctx._id.toInteger()` looks like it ought to work.

> [@Steve\_Suh](#):
>
> On a different note, is there a way to have the reindexing call pull in values outside of the document?

Not really. I had someone ask me about being able to pull any named\_queries from the matches which seemed like a good idea. I haven't built support for it, nor even investigated it. I expect it should be possible though.

You shouldn't be able to make any external calls during the script but you can certainly pass parameters to it. Everything in the `params` field that you send in should be available.

---

<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 5, 2017, 10:30pm UTC](https://discuss.elastic.co/t/reindex-scripting-help/57046/5 "2017-07-05T22:30:37Z")

</div>


