Attempting to reindex lat and lon as a geopoint using Dev Tools. Error: was expecting a colon to separate field name and value

I am attempting to reindex data that was originally uploaded as individual lat and lon strings into a single geo_point. In Dev Tools I attempted to use the following

POST _reindex
{
"source": {
"index": "ais_ben_test"
},
"dest": {
  "index": "ais_ben_geod"
 },
 "script": {
    "lang": "painless",
    "source": "ctx._source['GEO_POINT'] = ctx._source['LAT'] + ", " + ctx._source['LON']"
 }
}

I am getting the following error from my code

{ "error": {
"root_cause": [
  {
    "type": "x_content_parse_exception",
    "reason": "[10:67] [script] failed to parse object"
  }
],
"type": "x_content_parse_exception",
"reason": "[10:67] [reindex] failed to parse field [script]",
"caused_by": {
  "type": "x_content_parse_exception",
  "reason": "[10:67] [script] failed to parse object",
  "caused_by": {
    "type": "json_parse_exception",
    "reason": "Unexpected character ('}' (code 125)): was expecting a colon to separate field name and value\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@491171b5; line: 11, column: 4]"
  }
}

},
"status": 400
}

I have tried reformatting with a colon added at multiple areas of line 11 but none of my attempts have been successful. Any help would be appreciated.

Make sure to set up the ais_ben_geod index before running the command to map your field as a geo_point. Then you just need to escape the quotes around the comma. So the last line of your script will be "source": "ctx._source['GEO_POINT'] = ctx._source['LAT'] + \", \" + ctx._source['LON']"

PUT ais_ben_geod
{}

PUT ais_ben_geod/_mapping
{
  "properties": {
    "GEO_POINT": {
      "type": "geo_point"
    }
  }
}

POST _reindex
{
"source": {
"index": "ais_ben_test"
},
"dest": {
  "index": "ais_ben_geod"
 },
 "script": {
    "lang": "painless",
    "source": "ctx._source['GEO_POINT'] = ctx._source['LAT'] + \", \" + ctx._source['LON']"
 }
}

Thanks! I ended up using a slightly different indexing method but your advice was spot on.

POST _reindex
{
  "source": {
    "index": "ais_2016_nov_zone11_enriched"
  },
  "dest": {
    "index": "ais_2016_nov_zone11_enriched2"
  },
  "script": {
    "inline": "ctx._source.GEO_POINT = ctx._source.LAT + ' , ' + ctx._source.LON"
  }
}

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