Reputation: 77
I would like to perform geolocation queries with elasticsearch on my dataset which looks like this:
{"index": {"_index": "city","_type":"city_info", "_id":0} }
{"fields": { "city" : "AGAWAM",
"loc" : [ -72.622739, 42.070206 ],
"pop" : 15338, "state" : "MA"},
"id" : "01001" ,
"type" : "add"}
...
I am able to perform a lot of queries or aggregates without any problems but when it comes to a query with a geodistance filter or anything working on geographic coordinates, it doesn't work. Here is my mapping test:
PUT /city/_mappings
{
"properties": {
"fields.loc": {
"type": "geo_point"
}
}
}
I get this error.
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
}
],
"type" : "illegal_argument_exception",
"reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
},
"status" : 400
}
So it seems my "fields.loc" is a float whereas in the JSON it is an array with float values in. I tried to see what was the actual type of "loc" and it is indeed a float, which i don't understand why:
GET /city/_mapping
{
"city" : {
"mappings" : {
"properties" : {
"fields" : {
"properties" : {
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"loc" : {
"type" : "float"
...
So I don't understant, or rather I don't how to modify "loc" from a float to a geo_point. As I am a beginner with elasticsearch, I am only using elasticsearch and kibana for cURL.
Upvotes: 1
Views: 73
Reputation: 16895
Once you set the datatype implicitly to float (by bulk-syncing, as you probably did), it's gonna be difficult to convert the floats to geo_points.
I'd recommend dropping the index, setting the correct mapping with the geo_point
datatype and resyncing everything.
In case you'd like to go deeper, have a look at the _reindex
api. Here's a quick tut. That's something you'll probably face when your system runs in a production environment where dropping is now an option.
FYI, using a custom _doc type is deprecated.
Upvotes: 1