elasticsearch Geo Distance Query
elasticsearch Query Distance Geo
2023-09-14 08:57:38 时间
Geo Distance Query
过滤器文档只包括在一个特定距离内存在于一个地理点上的命中。假设下列映射和索引文档:
PUT /my_locations { "mappings": { "_doc": { "properties": { "pin": { "properties": { "location": { "type": "geo_point" } } } } } } } PUT /my_locations/_doc/1 { "pin" : { "location" : { "lat" : 40.12, "lon" : -71.34 } } }
然后,可以使用 geo_distance 过滤器来执行下列简单查询:
GET /my_locations/_search { "query": { "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "200km", "pin.location" : { "lat" : 40, "lon" : -70 } } } } } }
可以接受的格式
同样地,geo_point 类型可以接受地理点的不同表示,过滤器也可以接受它:
Lat Lon 作为属性
GET /my_locations/_search { "query": { "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : { "lat" : 40, "lon" : -70 } } } } } }
Lat Lon 作为数组
写成[lon, lat]格式,是为了符合GeoJson
GET /my_locations/_search { "query": { "bool" : { "must" : { "match_all" : {} }, "filter" : { "geo_distance" : { "distance" : "12km", "pin.location" : [-70, 40] } } } } }
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" } } } } }
参数
如下是用filter中允许使用的参数:
distance:圆的半径以指定的位置为中心。进入这个圆的点被认为是匹配的。可以在不同的单元中指定距离。
distance_type:如何计算距离。可以是arc(默认),也可以是平面(更快,但在长距离和靠近两极的地方是不准确的)。
_name:可选名称字段来识别查询
validation_method:设置为忽略不正确的纬度或经度的geo点,设置为强制再尝试并推断正确的坐标(默认是严格的)
geo_point Type
过滤器要求在相关字段上设置geo_point类型。
Multi Location Per Document
geo_distance过滤器可以处理每个文档的多个位置/点。一旦一个位置/点与过滤器匹配,文档就会被包含在过滤器中。
Ignore Unmapped
当设置为true时,无知的未映射选项将忽略一个未映射的字段,并且不会匹配该查询的任何文档。这在查询可能有不同映射的多个索引时非常有用。当设置为false(默认值)时,如果字段没有映射,查询将抛出异常。
相关文章
- 【Spring Boot】Spring Boot之使用 Spring Data Elasticsearch 整合elasticsearch
- Elasticsearch 连接ES的两种方式
- elasticsearch学习之根据发布时间设置衰减函数
- elasticsearch索引路径规则
- linuxea:ELK5.5-elasticsearch-x-pack破解
- ElasticSearch 5.0及head插件安装
- ELK(ElasticSearch+Logstash+ Kibana)搭建实时日志分析平台
- ElasticSearch安装拼音插件 elasticsearch-analysis-pinyin
- Elasticsearch NEST – Examples for mapping between Query and C#
- .net Elasticsearch 学习入门笔记
- Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询
- ElasticSearch Bulk 源码解析
- Elasticsearch-SQL
- Elasticsearch cat Apis
- Elasticsearch教程(六) elasticsearch Client创建
- Elasticsearch教程(七) elasticsearch Insert 插入数据(Java)
- Elasticsearch教程(九) elasticsearch 查询数据 | 分页查询
- Elasticsearch数据库优化实战:让你的ES飞起来
- elasticsearch学习一、安装和配置
- Elasticsearch 6.x版本全文检索学习之Search的运行机制
- 生产环境elasticsearch的配置建议
- elasticsearch function_score Query——文档排序结果的最后一道墙
- elasticsearch mappings之dynamic的三种状态
- ElasticSearch_10_ES和SpringBoot版本对应关系