Reindex fails with array mapped to geo_point

I'm attempting to reindex after changing the mapping of one field from type text to type geo_point.

The existing data in the source index looks like (but the lat_long mapping type = text):

        "location" : {
            "lat_long" : [
              "49.266498",
              "-122.998938"
            ],

how ever on the _reindex api call I get the following failures:

      "cause": {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [location.lat_long] of type [geo_point]",
        "caused_by": {
          "type": "parse_exception",
          "reason": "unsupported symbol [.] in geohash [49.228065]",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "unsupported symbol [.] in geohash [49.228065]"
          }

You need to cast the text values to double, otherwise it thinks it is a geohash input and fails.

For example this works for me (My mapping is slightly different but it should be easy to modify it for your needs):

POST _reindex
{
  "source": {
    "index": "src"
  },
  "dest": {
    "index": "tgt"
  },
  "script": {
    "source": "ctx._source.my_point[0]  = Double.parseDouble(ctx._source.my_point[0]); ctx._source.my_point[1] = Double.parseDouble(ctx._source.my_point[1]);",
    "lang": "painless"
  }
} 

Thanks, that makes sense, but I'm running into the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "ctx._source.location.lat_long[1] = Double.parseDouble(ctx._source.location.lat_long[0]);",
          "                                                                                   ^---- HERE"
        ],
        "script": "ctx._source.location.lat_long[0] = Double.parseDouble(ctx._source.location.lat_long[1]); ctx._source.location.lat_long[1] = Double.parseDouble(ctx._source.location.lat_long[0]);",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "ctx._source.location.lat_long[1] = Double.parseDouble(ctx._source.location.lat_long[0]);",
      "                                                                                   ^---- HERE"
    ],
    "script": "ctx._source.location.lat_long[0] = Double.parseDouble(ctx._source.location.lat_long[1]); ctx._source.location.lat_long[1] = Double.parseDouble(ctx._source.location.lat_long[0]);",
    "lang": "painless",
    "caused_by": {
      "type": "class_cast_exception",
      "reason": "Cannot cast java.lang.Double to java.lang.String"
    }
  },
  "status": 500
}

My Java isn't the greatest.

Looks like you might have a mixture of Doubles and test in your original source. You might want to call toString() method before parsing it to Double. I added some extra checks in case you have missing values:

POST _reindex
{
  "source": {
    "index": "src"
  },
  "dest": {
    "index": "tgt"
  },
  "script": {
    "source": "if (ctx._source.my_point != null && ctx._source.my_point.length == 2) {ctx._source.my_point[0]  = Double.parseDouble(ctx._source.my_point[0].toString()); ctx._source.my_point[1] = Double.parseDouble(ctx._source.my_point[1].toString());}",
    "lang": "painless"
  }
} 

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