Well, I have an index with documents that have geopoints as arrays of doubles. But it turns out that the longitude and latitude are in the wrong order, i.e., instead of [lon, lat]
the arrays are like [lat, lon]
. Is there any way to switch those values on all documents of the index without having to recreate them all again? Or change the format of the geopoints from an array to a string, so the data for them becomes "lat, lon"
? So far, the solution I found was to recreate the whole dataset again, which in this case is very time consuming to be practical.
Asked
Active
Viewed 480 times
0

Jose Ramirez
- 381
- 6
- 20
1 Answers
2
You could use the update by query API in order to update all documents and swap the coordinates, like this:
POST your_index/_update_by_query
{
"script": {
"inline": "ctx._source.location = [ctx._source.location[1], ctx._source.location[0]]",
"lang": "painless"
},
"query": {
"match_all": {}
}
}

Val
- 207,596
- 13
- 358
- 360
-
Thanks :) for some reason I was trying to do something like this, but it wasn't working; I was trying to update the location filed to have a string instead of an array with the values swapped. But well, this one worked perfectly – Jose Ramirez Apr 26 '17 at 08:40