0
votes

I have index that contains two fields: longitude and latitude that are stored as float. I want to create new index and copy data from the first one but with different mappings. I use reindex api with elastic processors which can rename fields and give them different data types. When i try to create field with type "geo_point" it fails.

"type": "parse_exception",
       "reason": "[type] type [geo_point] not supported, cannot convert field.",

but when i create new index i am able to create field with "geo_point" type. i tried different workarounds but documentation says that with geo queries you can only use "geo_point" type. is there any solution?

{
  "description": "test pipe",
  "processors": [
    {
      "convert": {
        "field": "location", 
        "type": "geo_point"
      }
    }
  ]
}

added pipe definition.

1
Please show your ingest pipeline definitionVal
sorry for being so late:) added pipeline definition.Taras Fityo
Can you also show your mapping and a sample document, please?Val
Basically the problem is that this pipe is not valid, kibana shows error, meaning that any field can not be converted to geo_point type. Error happens when i want to create this pipe.Taras Fityo
Do you actually have a field called location? Can you show what the pipeline creation error is?Val

1 Answers

0
votes

OK, let's say that your current index mapping looks like this:

PUT oldindex
{
  "mappings": {
    "doc": {
      "properties": {
        "latitude": {
          "type": "float"
        },
        "longitude": {
          "type": "float"
        }
      }
    }
  }
}

You need to create a new index with the proper mapping, as follows

PUT newindex
{
  "mappings": {
    "doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

And then, you can simply leverage the reindex API to copy the old index into the new one with some additional scripting to create the location field:

POST _reindex
{
  "source": {
    "index": "oldindex",
  },
  "dest": {
    "index": "newindex"
  },
  "script": {
    "source": "ctx._source.location = ['lat': ctx._source.latitude, 'lon': ctx._source.longitude]; ctx._source.remove('latitude'); ctx._source.remove('longitude'); "
  }
}

And you're good to go with the location field in your new shiny index!