【问题标题】:Elasticsearch 2.x: Error with geo_point with Mongodb and MongoosasticElasticsearch 2.x:使用 Mongodb 和 Mongoosastic 的 geo_point 出错
【发布时间】:2016-08-11 20:12:35
【问题描述】:

哟!过去几天在处理 elasticsearch 2.x 中的“geo_point”映射时遇到了一些问题。在尝试映射我的模拟数据以包含“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> ... }

它默认将我的“坐标”保存为双精度类型。我确保在使用我的 mongodb 集合中的数据播种 ES 之前运行上述脚本。我可以使用他们的 geoNear 函数很好地查询 Mongo,但出于性能原因,需要 ES 来进行地理查询。

任何帮助都会很棒!

【问题讨论】:

    标签: curl elasticsearch geolocation geospatial elasticsearch-2.0


    【解决方案1】:

    由于您的 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\"}}}}}"
    

    【讨论】:

    • 感谢您的回答!现在完美运行。
    • 太棒了,很高兴它有帮助!
    猜你喜欢
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    相关资源
    最近更新 更多