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"
          }
        }
      }
    }
  }
}
相关推荐
Elastic 中国社区官方博客12 小时前
使用真实 Elasticsearch 进行高级集成测试
大数据·数据库·elasticsearch·搜索引擎·全文检索·jenkins·集成测试
好记性+烂笔头12 小时前
4 Spark Streaming
大数据·ajax·spark
好记性+烂笔头16 小时前
3 Flink 运行架构
大数据·架构·flink
字节侠16 小时前
Flink2支持提交StreamGraph到Flink集群
大数据·flink·streamgraph·flink2·jobgraph
画船听雨眠aa19 小时前
gitlab云服务器配置
服务器·git·elasticsearch·gitlab
好记性+烂笔头20 小时前
4 Hadoop 面试真题
大数据·hadoop·面试
好记性+烂笔头20 小时前
10 Flink CDC
大数据·flink
赵渝强老师1 天前
【赵渝强老师】Spark RDD的依赖关系和任务阶段
大数据·缓存·spark
小小のBigData1 天前
【2025年更新】1000个大数据/人工智能毕设选题推荐
大数据·人工智能·课程设计
risc1234561 天前
【Elasticsearch 】悬挂索引(Dangling Indices)
大数据·elasticsearch·搜索引擎