在距某个geopoint的给定距离内匹配“geo_point”和“geo_shape”值。

例如:

假设以下文档已编制索引:

PUT /my_locations
{"mappings": {"properties": {"pin": {"properties": {"location": {"type": "geo_point"}}}}}
}PUT /my_locations/_doc/1
{"pin": {"location": {"lat": 40.12,"lon": -71.34}}
}PUT /my_geoshapes
{"mappings": {"properties": {"pin": {"properties": {"location": {"type": "geo_shape"}}}}}
}PUT /my_geoshapes/_doc/1
{"pin": {"location": {"type" : "polygon","coordinates" : [[[13.0 ,51.5], [15.0, 51.5], [15.0, 54.0], [13.0, 54.0], [13.0 ,51.5]]]}}
}

使用geo_distance过滤器匹配另一个geopoint指定距离内的geo_point值:

GET /my_locations/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "200km","pin.location": {"lat": 40,"lon": -70}}}}}
}

使用相同的过滤器匹配给定距离内的geo_shape:

GET my_geoshapes/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "200km","pin.location": {"lat": 40,"lon": -70}}}}}
}

要同时匹配geo_point和geo_shape值,请搜索两个索引:

GET my_locations,my_geoshapes/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "200km","pin.location": {"lat": 40,"lon": -70}}}}}
}

Accepted Formats

与geo_point类型大致相同,可以接受geo point的不同表示方式,过滤器也可以接受它:

Lat Lon As Properties

GET /my_locations/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "12km","pin.location": {"lat": 40,"lon": -70}}}}}
}

Lat Lon As Array

[lon,lat]格式,注意,此处lon/lat的顺序,以符合GeoJSON。

GET /my_locations/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "12km","pin.location": [ -70, 40 ]}}}}
}

Lat Lon As String

格式为lat,lon。

GET /my_locations/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "12km","pin.location": "40,-70"}}}}
}

Geohash

GET /my_locations/_search
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": "12km","pin.location": "drm3btev3e86"}}}}
}

Elasticsearch——Geo-distance查询相关推荐

  1. Elasticsearch:Geo Point 和 Geo Shape 查询解释

    在本文中,我们将了解 Elasticsearch 的地理查询.如何设置映射和索引,并提供一些示例来说明如何查询数据. Elasticsearch 中的地理数据 Elasticsearch 允许你以两种 ...

  2. 02.elasticsearch bucket aggregation查询

    文章目录 1. bucket aggregation 查询类型概览 2. 数据准备 3. 使用样例 1. Terms Aggregation: 1. 普通的terms agg 2. 嵌套一个metri ...

  3. Elasticsearch实战——地理位置查询

    Elasticsearch实战--地理位置查询 文章目录 Elasticsearch实战--地理位置查询 1. 半径查询(geo_distance query) 2. 指定矩形内的查询(geo_bou ...

  4. 01.elasticsearch metric aggregation 查询

    文章目录 1. 数据准备 2. metric aggregation分类 3.使用样例 1 . Avg Aggregation : 求query出来的结果的average 值 2 . Weighted ...

  5. ES(Elasticsearch)基本查询总结(含docker安装,python操作)

    全栈工程师开发手册 (作者:栾鹏) 架构系列文章 官网:https://www.elastic.co/guide/index.html 搜索语法:https://www.elastic.co/guid ...

  6. elasticsearch geo DSL 和API对比学习-矩形/多边形/距离/距离排序/距离分段聚合/geo_shape内含-相交-相离

    直接上代码,包括多种geo相关查询===>>>矩形/多边形/距离/距离排序/距离分段聚合/geo_shape内含-相交-相离 @RunWith(SpringRunner.class) ...

  7. 03.elasticsearch pipeline aggregation查询

    文章目录 1. pipeline aggregation查询语法 1. 符号代表 2. 聚合层级 2. pipeline aggregation 查询类型概览 1. sibling aggregati ...

  8. java操作elasticsearch实现前缀查询、wildcard、fuzzy模糊查询、ids查询

    1.前缀查询(prefix) //prefix前缀查询 @Testpublic void test15() throws UnknownHostException {//1.指定es集群 cluste ...

  9. 【Elasticsearch】解决Elasticsearch HTTP方式查询报SocketTimeoutException的问题 Connection reset by peer

    1.概述 转载:解决Elasticsearch HTTP方式查询报SocketTimeoutException的问题(待验证) 这个问题,和这个问题很像.参考 [es]ES RestHighLevel ...

  10. 【Elasticsearch】 Elasticsearch 多字段查询 best_fields、most_fields、cross_fields,傻傻分不清楚?

    1.概述 转载:Elasticsearch 多字段查询 best_fields.most_fields.cross_fields,傻傻分不清楚? 1.1 题记 Multi-match query 的目 ...

最新文章

  1. 备战 ‘金三银四’ 必备超多软件测试面试题全在这里
  2. 【图灵有聊】说好的安全呢?
  3. 【Java Web前端开发】HTML表单和CSS部分
  4. [编写高质量代码:改善java程序的151个建议]建议31-在接口中不要存在实现代码...
  5. 【渝粤教育】国家开放大学2018年春季 0675-21T中级财务会计(2) 参考试题
  6. css外观样式 1204
  7. 给button加href
  8. luogu1005矩阵取数游戏题解--区间DP
  9. 解决Python print 输出文本显示 gbk 编码错误问题
  10. 计算机语言echo off什么意思,批处理文件的@echo off是什么意思?
  11. 概率论中两个独立连续随机变量X,Y,变量Z=X+Y的密度函数为X,Y的卷积与特征函数原理
  12. Android 热补丁动态修复
  13. 电子书 “已取消到该网页的导航”或“导航已取消”解决方法
  14. 台式计算机关闭屏幕快捷键,关闭电脑屏幕的快捷键
  15. 简单的mg动画制作方法,看到就是赚到 | 万彩动画大师
  16. Linux中的lvm动态扩容管理
  17. 在中国在行其道的智慧城市,为何折戟多伦多
  18. ECCV 2022,两位华人学者摘得最佳论文奖,本科来自清华、浙大
  19. 2021香港排名前十的现货伦敦金正规平台排行榜
  20. 空域变换-直方图局部处理(CLAHE)

热门文章

  1. MySQL的简介及MySQL和MySQL-front的下载安装
  2. NOC C++ 全国中小学信息技术创新与实践大赛(NOC):软件创意编程赛道
  3. GHOST双系统(XP和VISTA)详细图解教程
  4. 动漫高清修复,修复视频清晰度
  5. Reloaded modules:在Spyder运行时错误
  6. 来~打包实现小程序动态分享图一条龙服务( ¨̮ )
  7. 充电倍率、温度对电池特性的影响
  8. BZOJ 1218(二维前缀和)
  9. uefi安装android x86,Android-x86 8.1 RC1发布 支持从UEFI系统引导和安装
  10. HDR in OpenGL