Search code examples
curlelasticsearchgeolocationgeospatialelasticsearch-2.0

Elasticsearch 2.x: Error with geo_point with Mongodb and Mongoosastic


Yo! Having some problems there past ew days working through this error when working with the 'geo_point' mapping in elasticsearch 2.x. while trying to map my mock data to include the 'geo_point' I'm receiving an error in my console when running the below script:

curl -XDELETE localhost:9200/users

curl -XPOST localhost:9200/users -d "{"mappings":{"user":{"properties":{"coords":{"type":"geo_point"}}}}}"

{"error":{"root_cause":[{"type":"parse_exception","reason":"failed to parse source for create index"}],"type":"parse_exception","reason":"failed to parse source for create index","caused_by":{"type":"json_parse_exception","reason":"Unrecognized token 'geo_point': was expecting ('true', 'false' or 'null')\n at [Source: [B@4d7cc1ea; line: 1, column: 56]"}},"status":400}%

My mock data looks like:

{ ... "coords": [-84.370829, 33.756670] //<lon, lat> ... }

It defaults saved my 'coords' as type double. I'm making sure to run the above script before seeding ES with data from my mongodb collections. I'm able to query Mongo just fine using their geoNear function but for performance reasons, need ES to do the geo queries instead.

Any help would be great!


Solution

  • Since your JSON contains double quotes, you simply need to either use single quotes...

    curl -XPOST localhost:9200/users -d '{"mappings":{"user":{"properties":{"coords":{"type":"geo_point"}}}}}'
    

    ...or escape your double quotes in the JSON

    curl -XPOST localhost:9200/users3 -d "{\"mappings\":{\"user\":{\"properties\":{\"coords\":{\"type\":\"geo_point\"}}}}}"