elasticsearch高级功能系列之geo地理坐标

参考:https://blog.csdn.net/u010503427/article/details/81665991

1、首先创建mapping

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

2、导入数据

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
}
}
}
}
}

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)查询给定1000KM距离范围内的点

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

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
}
]
}
}
}
}

 

posted @ 2021-08-16 11:30  飞鹰之歌  阅读(309)  评论(0)    收藏  举报