##geo_point地理位置搜索
##索引
PUT my_location
{
"mappings": {
"properties": {
"location":{
"type": "geo_point"
}
}
}
}
##插入数据
POST my_location/_bulk
{"index":{"_id":2}}
{"text":"上海站","location":{"lat":31.256224,"lon":121.462311}}
{"index":{"_id":3}}
{"text":"五一广场","location":"POINT (121.460186 31.251281)"}
{"index":{"_id":4}}
{"text":"交通公园","location":"31.253531,121.473939"}
{"index":{"_id":5}}
{"text":"万业远景大厦","location":[121.448215,31.26229]}
##根据地理位置查询
GET /my_location/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 31.265395,
"lon": 121.444075
},
"bottom_right": {
"lat": 31.253845,
"lon": 121.468417
}
}
}
}
}
}
}
##根据距离distance搜索
GET my_location/_search
{
"query": {
"bool": {
"must": [
{"match_all": {}}
],
"filter": [
{
"geo_distance": {
"distance": "2000km",
"location": {
"lat": 40.73,
"lon": -74.1
}
}
}
]
}
}
}
##基础地理位置进行聚合分析
##如0~100m有几个酒店
##100~300m有几个酒店
GET my_location/_search
{
"size": 0,
"aggs": {
"aggs_by_distance": {
"geo_distance": {
"field": "location",
"origin": {
"lat": 31.3,
"lon": 121.4
},
"unit": "km",
"distance_type": "plane",
"ranges": [
{
"from": 0,
"to": 5
},
{
"from": 5,
"to": 10
},
{
"from": 10,
"to": 100
}
]
}
}
}
}