Reputation: 1513
I have a mapping like below:
{
"my_locations": {
"aliases": {
},
"mappings": {
"_doc": {
"properties": {
"location": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
I know that if the field type of location is "geo_point" then I can use following geo distance query.
GET /my_locations/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}
I read that I cannot change the field type for location from text to geo_point(from elastic search documentation and stackoverflow) and I already have many data. So how can I find the location that are within the certain range from my input location?
Upvotes: 0
Views: 38
Reputation: 217564
First, you need to create a new index with the correct data type
PUT my_locations_2
{
"mappings": {
"_doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
Then you can use the reindex API in order to copy the data from the old index to the new one:
POST _reindex
{
"source": {
"index": "my_locations"
},
"dest": {
"index": "my_locations_2"
}
}
Upvotes: 1