put my_index
{
"mappings":{
"my_type":{
"properties":{
"location":{
"type":"geo_point" ----指定是这种类型的type
}
}
}
}
}
put my_index/my_type/1
{
"text":"GEO-point",
"location":{
"lat":41.12, 经度
"lon":-71.31 纬度
}
}
GET /my_index/my_type/_search
{
"query": {
"geo_bounding_box": { ----以1为左上角,2为右下角的一个矩形范围内的坐标搜索
"location": {
"top_left": { ---1
"lat": 56,
"lon": -72
},
"bottom_right": {---2
"lat": 50,
"lon": -74
}
}
}
}
}
get hotel_app/hotels/_search
{
"query":{
"bool": {
"must":[{
"match_all":{}
}
],
"filter": {
"geo_distance": { ----------距离100km内可以搜索到的坐标
"distance": "100km",
"pin.location": { ------1
"lat": 40.73,
"lon": -74.1
}
}
}
}
}
}
GET /hotel_app/hotels/_search
{
"size": 0,
"aggs": {
"agg_by_distance_range": {
"geo_distance": {
"field": "pin.location",
"origin": {
"lat": 40,
"lon": -70
},
"unit": "mi",
"ranges": [
{
"to": 100
},
{
"from": 100,
"to": 300
},
{
"from": 300
}
]
}
}
}
}