Elasticsearch 2.x:geo_point与Mongodb和Mongoosastic出错

时间:2016-08-11 20:12:35

标签: curl elasticsearch geolocation geospatial elasticsearch-2.0

哟!在使用' geo_point'处理此错误的过去几天遇到一些问题。弹性搜索中的映射2.x.在尝试映射我的模拟数据时,包括' geo_point'运行以下脚本时,我在控制台中收到错误:

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}%

我的模拟数据如下:

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

默认保存了我的&#39; coords&#39;作为类型double。我确保在使用我的mongodb集合中的数据播种ES之前运行上面的脚本。我能够使用他们的geoNear函数很好地查询Mongo但是出于性能原因,需要ES来进行地理查询。

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

由于您的JSON包含双引号,您只需要使用单引号...

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

...或者在JSON

中转义双引号
curl -XPOST localhost:9200/users3 -d "{\"mappings\":{\"user\":{\"properties\":{\"coords\":{\"type\":\"geo_point\"}}}}}"