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"
          }
        }
      }
    }
  }
}
相关推荐
SelectDB30 分钟前
Doris Arrow Flight SQL 高速读取协议实战:与 Snowflake 客户端取数链路对照
大数据·数据库·数据分析
爱签AI电子合同1 小时前
电子合同全维度实测与选型指南
大数据·人工智能
AI办公探索者1 小时前
从SaaS到本地部署:大模型推理成本优化与8888元私有化方案的技术解析
大数据·人工智能
做运维的阿瑞1 小时前
云项目可观测性与成本治理:告警、日志、Dashboard 与预算标签
大数据·云原生·云计算·terraform
4SAPI2 小时前
多国产模型混合调度与企业级治理生产选型指南:4SAPI、硅基流动与 OpenRouter 的架构权衡
大数据·人工智能·架构·php
智购科技自动售货机厂家2 小时前
让AI经营自动售货机:从Project Vend看工具权限与业务规则~YH
大数据·服务器·单片机·嵌入式硬件·深度学习
数字新视界2 小时前
空调控制器AIRC800的智能化管理与应用实践
大数据·服务器·数据库·动环监控系统·动力与环境监控系统
isfox3 小时前
ReduceTask工作机制
大数据
蹄蹄4 小时前
从“一次性检测“到“年度服务“:检测机构收入结构变了,合同和应收账款也要跟着变
大数据·数据库·人工智能
YIN_尹4 小时前
【git原理与使用】git初识与安装
大数据·git·elasticsearch