本文主要是介绍Elasticsearch7.17.7操作geo_point类型数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目前使用的elasticsearch版本是7.17.7
有一个index,其中mapping的内容如下:
{"city" : {"aliases" : { },"mappings" : {"properties" : {"city" : {"type" : "keyword"},"location" : {"type" : "geo_point"}}}}
}
其中location字段的类型设置为geo_point
,可以传递经纬度。
支持的数据格式如下,ES会自动将lon
转化为经度,lat
转化为维度:
{"city":"鄣山大峡谷风景区","location": {"lon": "118.74", "lat": "30.08"}}
{"city":"九寨沟风景区","location": {"lon": "103.91", "lat": "33.26"}}
{"city":"水绘园","location": {"lon": "120.56", "lat": "32.39"}}
{"city":"关山国家地质公园八里沟园区","location": {"lon": "113.58", "lat": "35.59"}}
{"city":"Sapu Padidu","location": {"lon": "125.266937", "lat": "5.91722"}}
{"city":"将军石山庄","location": {"lon": "130.11", "lat": "47.23"}}
{"city":"Saipan","location": {"lon": "145.7", "lat": "15.1"}}
{"city":"六峰山","location": {"lon": "109.28", "lat": "22.41"}}
{"city":"小河古村评梅景区","location": {"lon": "113.64", "lat": "37.84"}}
根据矩形搜索
输入的是矩形形状的左上经纬度和右下经纬度,查询语句如下:
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_bounding_box": {"location": {"top_left": {"lat": 左上纬度,"lon": 左上经度},"bottom_right": {"lat": 右下纬度,"lon": 右下经度}}}}}}
}
es会将包含在当前矩形范围内的city
搜索出来。
根据圆形和半径搜索
es还支持根据圆形和半径来搜索数据:
搜索语句如下:
{"query": {"bool": {"must": {"match_all": {}},"filter": {"geo_distance": {"distance": str(距离) + "m","distance_type": "arc","_name": "optional_name","location": {"lat": 圆心的纬度,"lon": 圆心的经度}}}}}
}
其中distance
指的是半径的大小,单位可以是m
、km
等等。会将当前半径下面的所有点搜索出来。
这篇关于Elasticsearch7.17.7操作geo_point类型数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!