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"
          }
        }
      }
    }
  }
}
相关推荐
代码匠心9 分钟前
从零开始学Flink:事件驱动
java·大数据·flink·大数据处理
Lx3521 小时前
Flink自定义函数:UDF、UDAF和UDTF实战
大数据
一个处女座的暖男程序猿2 小时前
2G2核服务器安装ES 7X版本
服务器·elasticsearch·jenkins
jiuweiC2 小时前
常用es sql
大数据·sql·elasticsearch
武子康4 小时前
大数据-143 ClickHouse 实战MergeTree 分区/TTL、物化视图、ALTER 与 system.parts 全流程示例
大数据·后端·nosql
Hello.Reader4 小时前
用 Spark Shell 做交互式数据分析从入门到自包含应用
大数据·数据分析·spark
GeminiJM4 小时前
优化Elasticsearch批量写入性能:从单分片瓶颈到多索引架构
elasticsearch·架构·jenkins
得物技术4 小时前
大模型如何革新搜索相关性?智能升级让搜索更“懂你”|得物技术
算法·搜索引擎·排序算法
Elasticsearch5 小时前
通过混合搜索重排序提升多语言嵌入模型的相关性
elasticsearch
qq_12498707535 小时前
基于hadoop的电商用户行为分析系统(源码+论文+部署+安装)
大数据·hadoop·分布式·毕业设计