Elasticsearches通过坐标位置实现对附近人的搜索

作者:Jeff的技术栈 时间:2023-05-23 16:16:12 

一 创建mapping

PUT test
{
 "mappings": {
   "test":{
     "properties": {
       "location":{
         "type": "geo_point"
       }
     }
   }
 }
}

二 导入数据

POST test/test
{
 "location":{
   "lat":12,
   "lon":24
 }
}

三 查询

3.1根据给定两个点组成的矩形,查询矩形内的点

GET test/test/_search
{
 "query": {
   "geo_bounding_box": {
     "location": {
       "top_left": {
         "lat": 28,
         "lon": 10
       },
       "bottom_right": {
         "lat": 10,
         "lon": 30
       }
     }
   }
 }
}

3.2根据给定的多个点组成的多边形,查询范围内的点

GET test/test/_search
{
 "query": {
   "geo_polygon": {
     "location": {
       "points": [
         {
           "lat": 11,
           "lon": 25
         },
         {
           "lat": 13,
           "lon": 25
         },
         {
           "lat": 13,
           "lon": 23
         },
         {
           "lat": 11,
           "lon": 23
         }
       ]
     }
   }
 }
}

3.3查询给定1000KM距离范围内的点

GET test/test/_search
{
 "query": {
   "geo_distance": {
     "distance": "1000km",
     "location": {
       "lat": 12,
       "lon": 23
     }
   }
 }
}

3.4查询距离范围区间内的点的数量

GET test/test/_search
{
 "size": 0,
 "aggs": {
   "myaggs": {
     "geo_distance": {
       "field": "location",
       "origin": {
         "lat": 52.376,
         "lon": 4.894
       },
       "unit": "km",
       "ranges": [
         {
           "from": 50,
           "to": 30000
         }
       ]
     }
   }
 }
}

来源:https://www.cnblogs.com/guyouyin123/p/13308748.html

标签:Elasticsearches,位置坐标,附近人,搜索
0
投稿

猜你喜欢

  • django 消息框架 message使用详解

    2021-06-21 17:22:29
  • 在ORACLE里设置访问多个SQL Server数据库

    2007-08-17 10:18:00
  • SQL Server之SELECT INTO 和 INSERT INTO SELECT案例详解

    2024-01-22 01:11:56
  • Python中矩阵库Numpy基本操作详解

    2021-07-09 18:13:05
  • python十进制转二进制的详解

    2023-06-07 23:39:33
  • Linux 7下脚本安装配置oracle 11g r2教程

    2024-01-13 13:35:56
  • 如何通过Python的pyttsx3库将文字转为音频

    2023-01-11 19:54:59
  • Python字典中的键映射多个值的方法(列表或者集合)

    2021-03-07 04:50:40
  • python获取从命令行输入数字的方法

    2021-08-23 15:19:02
  • Python matplotlib绘制散点图配置(万能模板案例)

    2023-08-02 23:04:18
  • MySQL之导出整个及单个表数据的操作

    2024-01-17 00:52:02
  • python调用stitcher类自动实现多个图像拼接融合功能

    2022-11-30 05:11:40
  • linux中使用boost.python调用c++动态库的方法

    2023-01-19 19:21:03
  • python中函数的返回值及类型详解

    2023-02-17 10:58:11
  • Vue中qs插件的使用详解

    2023-07-02 17:07:06
  • Python 实现简单的电话本功能

    2021-11-16 09:47:58
  • python 请求服务器的实现代码(http请求和https请求)

    2023-07-10 08:23:58
  • IE7 与 IE6 的模式窗口尺寸差异

    2008-03-06 13:49:00
  • php中运用http调用的GET和POST方法示例

    2023-11-23 02:39:35
  • 一文吃透Go的内置RPC原理

    2024-02-03 08:45:53
  • asp之家 网络编程 m.aspxhome.com