Reindex scripting help?

Here's my script:

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:

{
   "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

Looks like I can run any built in Groovy call. :slight_smile:

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.

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

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.