首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Elasticsearch存储geo数据搜索

Elasticsearch存储geo数据搜索

作者头像
XING辋
发布2019-03-26 11:00:37
发布2019-03-26 11:00:37
9990
举报
文章被收录于专栏:M莫的博客M莫的博客

使用geo_point类型

创建索引

123456789101112131415161718

curl -XPOST 'http://localhost:9200/weixin_discovery_market_location' -d ' { "aliases" : { "alias_weixin_discovery_market_location" : {} }, "mappings": { "type": { "properties": { "marketName":{ "type": "string" }, "location": { "type": "geo_point" } } } } }'

添加数据

12345678

curl -XPUT 'http://localhost:9200/weixin_discovery_market_location/type/1009' -d ' { "marketName": "真北商场", "location": { "lat": 41.12, "lon": -71.34 } }'

添加数据

12345678

curl -XPUT 'http://localhost:9200/weixin_discovery_market_location/type/1019' -d ' { "marketName": "吴中商场", "location": { "lat": 31.12, "lon": -51.34 } }'

查询指定geo 周边最近地址

123456789101112131415161718192021222324252627282930

curl -XPOST 'http://localhost:9200/weixin_discovery_market_location/type/_search' -d ' { "query": { "filtered": { "filter": { "geo_distance": { "distance": "91km", "location": { "lat": 31.12, "lon": -51.34 } } } } }, "sort": [ { "_geo_distance": { "location": { "lat": 31.12, "lon": -51.34 }, "order": "asc", "unit": "km", "distance_type": "plane" } } ] }'

使用geo_shape类型

创建索引

12345678910111213141516171819

curl -XPOST 'http://localhost:9200/weixin_discovery' -d ' { "aliases" : { "alias_weixin_discovery" : {} }, "mappings": { "type": { "properties": { "marketName":{ "type": "string" }, "location": { "type": "geo_shape", "points_only": true } } } } }'

添加数据

12345678

curl -XPUT 'http://localhost:9200/weixin_discovery/type/1009' -d ' { "marketName": "真北商场", "location": { "type": "point", "coordinates": [121.392496,31.245827] } }'

查询指定geo 1KM范围内的geo数据信息

12345678910111213141516

curl -XPOST 'http://localhost:9200/weixin_discovery/type/_search' -d ' { "query": { "geo_shape": { "location": { "shape": { "type": "circle", "radius": "1km", "coordinates": [ 121.391337,31.244654 ] } } } } }'

reference

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-03-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用geo_point类型
    • 创建索引
    • 添加数据
    • 添加数据
    • 查询指定geo 周边最近地址
  • 使用geo_shape类型
    • 创建索引
    • 添加数据
    • 查询指定geo 1KM范围内的geo数据信息
  • reference
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档