Reindex to add geo_point mapping

Hi @jbrowe
You are close but as the error says geo_points can not be dynamically converted type so you are going to need to do something like this. Create a little ingest pipelinee to help with the transformation

See if you can follow this along same principal you just need to change to fit your data

DELETE /city

# Put in non geo_point document 
POST /city/_doc
{
  "name": "north stamford",
  "location": {
    "lon": -73.572866,
    "lat": 41.142307
  }
}

GET /city/_search

GET /city/_mapping

DELETE /citynew

# Put the new mapping 
PUT /citynew
{
  "mappings": {
    "properties": {
      "name" : {"type" : "text"},
      "location_fixed": {
        "type": "geo_point"
      }
    }
  }
}

# check the mapping 
GET /citynew/_mapping

  
DELETE /_ingest/pipeline/convert_geo

# Create an ingest pipeline
# Sets the old location into the new geo_point field and drops the old location.
PUT /_ingest/pipeline/convert_geo
{
  "processors": [
    {
      "set": {
        "field": "location_fixed.lat",
        "value": "{{location.lat}}"
      }
    },
    {
      "set": {
        "field": "location_fixed.lon",
        "value": "{{location.lon}}"
      }
    },
    {
      "remove": {
        "field": "location"
      }
    }
  ]
}

#Now reindex using the ingest pipeline
POST _reindex/
{
  "source": {
    "index": "city"
  },
  "dest": {
    "pipeline": "convert_geo", 
    "index": "citynew"
  }
}

# Check out your new index 
GET /citynew/_search

Hope this Helps!

In the future you may want to use logstash to do the ingest and do the conversion before it ever gets to elastic search ... but that is another technique for another day...

1 Like