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"
          }
        }
      }
    }
  }
}
相关推荐
芯小途202622 分钟前
影视 AIGC 素材管理:改到第 108 版,为什么「块级去重」能把 TB 级素材压回百 GB(附估算脚本)
大数据·aigc
IanSkunk36 分钟前
视光中心建设复盘:从流程断层到组织能力的落地路径
大数据·人工智能
fanged1 小时前
Yocto1--环境搭建和验证
大数据·搜索引擎·嵌入式
微石科技2 小时前
社区卫生中心慢病管理怎么做?宁波微石科技智慧医康系统:一个平台管住趋势、随访、患者
大数据·人工智能·科技
大大大大晴天2 小时前
K8S 在大数据里的真正价值:适用场景、收益边界与不适合的地方
大数据·云原生
跨境小彭2 小时前
Temu半托管运营复盘:批量备货自动化实操解决方案
大数据·运维·自动化·跨境电商·temu
千里码aicood3 小时前
【区块链】一种面向稀疏车流量场景的车联网共识算法设计与实现
大数据
科技小E3 小时前
国标GB28181视频平台EasyGBS监控为什么会“瞎”:视频质量诊断EasyVQD如何揪出黑屏卡顿偏色
大数据·人工智能·音视频
2601_960017624 小时前
胶黏剂PLM选型指南:为什么垂直行业专用PLM更合适
大数据·人工智能