ES网格聚合

 

参考地址 Geohash 网格聚合 | Elasticsearch: 权威指南 | Elastic

es接口测试如下:

DELETE /museums

#创建索引
PUT  /museums
{
	"mappings": {
		"properties": {
			"location": {
				"type": "geo_point"
			}
		}
	}
}

#添加数据
POST /museums/_bulk?refresh
{"index":{"_id":1}}
{"location": {"lon":"52.374081","lat": "4.912350"}, "name": "NEMO Science Museum"}
{"index":{"_id":2}}
{"location": {"lon":"52.369219","lat": "4.901618"}, "name": "Museum HetRembrandthuis"}
{"index":{"_id":3}}
{"location": {"lon":"52.371667","lat": "4.914722"}, "name": "Nederlands Scheepvaartmuseum"}
{"index":{"_id":4}}
{"location": {"lon":"51.222900","lat": "4.405200"}, "name": "Letterenhuis"}
{"index":{"_id":5}}
{"location":  {"lon":"48.861111","lat": "2.336389"}, "name": "Musée du Louvre"}
{"index":{"_id":6}}
{"location": {"lon":"48.860000","lat": "2.327000"}, "name": "Musée d'Orsay"}


#查询数据
GET /museums/_search
{
  "query": {
    "match_all": {}
  }
}


#查询数据,精度 1-8  越大地图桶越小,分的组越多
POST /museums/_search?size=0
{
	"aggregations": {
		"large-grid": {
			"geohash_grid": {
				"field": "location",
				"precision": 3
			}
		}
		
	}
}



#查询数据,精度 1-8  越大地图桶越小,分的组越多
GET /museums/_search?size=0
{
	  "aggs": {
    "large-grid": {
      "geohash_grid": {
        "field":     "location",
        "precision": 3
      },
      "aggs": {
        "cell": { 
          "geo_bounds": {
            "field": "location"
          }
        }
      }
    }
  }
}


#指定矩形内查询数据,精度 1-8  越大地图桶越小,分的组越多
GET /museums/_search?size=3
{
  "query": {
    "constant_score": {
      "filter": {
        "geo_bounding_box": {
          "location": {
            "top_left": {
              "lon": "52.374081",
               "lat": "5.912350"
            },
            "bottom_right": {
              "lon": "52.374081",
              "lat": "4.912350"
            }
          }
        }
      }
    }
    
  }, 
	  "aggs": {
      "large-grid": {
        "geohash_grid": {
        "field":     "location",
        "precision": 5
      },
      "aggs": {
        "cell": { 
          "geo_bounds": {
            "field": "location"
          }
        }
      }
    }
  }
}


#指定桶的key查询数据,精度 1-8  越大地图桶越小,分的组越多
GET /museums/_search?size=3
{
  "query": {
    "constant_score": {
      "filter": {
        "geo_bounding_box": {
          "location": {
            "top_left": "t0v",
            "bottom_right": "t0v"
          }
        }
      }
    }
    
  }, 
	  "aggs": {
      "large-grid": {
        "geohash_grid": {
        "field":     "location",
        "precision": 5
      },
      "aggs": {
        "cell": { 
          "geo_bounds": {
            "field": "location"
          }
        }
      }
    }
  }
}





  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值