wordpress企业网站模板破解,百度官网推广平台电话,网站建设人员工资,企业网站建设的成本需求整理#xff1a;
geohash 7网格存储工作热度和学习热度数值#xff0c;支持随机区域多个范围的热度聚合#xff1b;
创建索引结构
索引文档需要包含 Geohash 网格、工作热度和学习热度等字段。可以在 Elasticsearch 中定义一个索引#xff0c;确保 location 字段的类…需求整理
geohash 7网格存储工作热度和学习热度数值支持随机区域多个范围的热度聚合
创建索引结构
索引文档需要包含 Geohash 网格、工作热度和学习热度等字段。可以在 Elasticsearch 中定义一个索引确保 location 字段的类型是 geo_point用于支持地理空间查询。
PUT /geohash_index
{mappings: {properties: {geohash: {type: keyword},location: {type: geo_point},work_heat: {type: integer},study_heat: {type: integer}}}
}插入数据
POST /geohash_index/_doc/1
{geohash: wx4g0f0,location: {lat: 39.9042,lon: 116.4074},work_heat: 100,study_heat: 50
}聚合查询
使用 Elasticsearch 的地理空间范围聚合 (geo_distance aggregation) 实现不同范围内的数据聚合比如 500m、1.5km、3km统计工作热度和学习热度。
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.range.GeoDistanceAggregationBuilder;
import org.elasticsearch.common.unit.DistanceUnit;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;public class GeoAggregationQuery {Autowiredprivate ElasticsearchRestTemplate elasticsearchRestTemplate;public void searchWithGeoAggregation() {// 构建地理空间范围聚合GeoDistanceAggregationBuilder geoDistanceAgg AggregationBuilders.geoDistance(geo_distance_agg, new GeoPoint(39.9042, 116.4074)).unit(DistanceUnit.METERS).field(location).addRange(0, 500) // 0-500米范围.addRange(500, 1500) // 500米-1.5公里范围.addRange(1500, 3000) // 1.5公里-3公里范围.subAggregation(AggregationBuilders.sum(total_work_heat).field(work_heat)) .subAggregation(AggregationBuilders.sum(total_study_heat).field(study_heat)); // 构建查询NativeSearchQuery searchQuery new NativeSearchQueryBuilder().withQuery(QueryBuilders.matchAllQuery()) .addAggregation(geoDistanceAgg).build();elasticsearchRestTemplate.search(searchQuery, YourEntityClass.class).getAggregations().asMap().forEach((name, agg) - {// 处理聚合结果例如输出各个范围内的热度总和System.out.println(name : agg);});}
}可以根据需求扩展查询条件例如增加 BoolQueryBuilder 来过滤特定条件的数据。同样可以通过修改距离和单位调整聚合的范围。
额外怎么评估最外围擦边的点要不要算在里面
1. 中心点与半径 每个距离范围如 500m、1.5km、3km是以你指定的中心点为原点计算的半径距离。在执行查询时Elasticsearch 通过 Haversine 公式或其他地理距离计算方法确定每个文档的地理位置是否在某个距离范围内。 2. 文档是否落入某个范围 • 如果文档的地理位置计算出的距离小于或等于给定范围例如 500m 或 1.5km那么这个文档会被算作属于这个距离范围的桶。 • 如果文档的地理位置超过了给定的范围那么它不会算作在该桶中。
具体实现
基于中心点计算距离的起点是你定义的中心点所有距离测量都是围绕这个点进行。严格的边界计算擦边的点如果距离与给定范围正好相等它会被算作属于该范围。 文章转载自: http://www.morning.qtzk.cn.gov.cn.qtzk.cn http://www.morning.zxfr.cn.gov.cn.zxfr.cn http://www.morning.lhsdf.cn.gov.cn.lhsdf.cn http://www.morning.njpny.cn.gov.cn.njpny.cn http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn http://www.morning.qbpqw.cn.gov.cn.qbpqw.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.tpnxj.cn.gov.cn.tpnxj.cn http://www.morning.fwrr.cn.gov.cn.fwrr.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.ryyjw.cn.gov.cn.ryyjw.cn http://www.morning.mtyhk.cn.gov.cn.mtyhk.cn http://www.morning.nhpgm.cn.gov.cn.nhpgm.cn http://www.morning.vjdofuj.cn.gov.cn.vjdofuj.cn http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn http://www.morning.cnfxr.cn.gov.cn.cnfxr.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.mzgq.cn.gov.cn.mzgq.cn http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn http://www.morning.qkxt.cn.gov.cn.qkxt.cn http://www.morning.rcbdn.cn.gov.cn.rcbdn.cn http://www.morning.lzjxn.cn.gov.cn.lzjxn.cn http://www.morning.rykx.cn.gov.cn.rykx.cn http://www.morning.rkdw.cn.gov.cn.rkdw.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.bpmmq.cn.gov.cn.bpmmq.cn http://www.morning.qhjkz.cn.gov.cn.qhjkz.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.mtmnk.cn.gov.cn.mtmnk.cn http://www.morning.dktyc.cn.gov.cn.dktyc.cn http://www.morning.bchfp.cn.gov.cn.bchfp.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.wgcng.cn.gov.cn.wgcng.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.bpmz.cn.gov.cn.bpmz.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.lkbyq.cn.gov.cn.lkbyq.cn http://www.morning.hkshy.cn.gov.cn.hkshy.cn http://www.morning.kndt.cn.gov.cn.kndt.cn http://www.morning.bygyd.cn.gov.cn.bygyd.cn http://www.morning.sogou66.cn.gov.cn.sogou66.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.rshkh.cn.gov.cn.rshkh.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.btgxf.cn.gov.cn.btgxf.cn http://www.morning.khxwp.cn.gov.cn.khxwp.cn http://www.morning.ntlxg.cn.gov.cn.ntlxg.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.chhhq.cn.gov.cn.chhhq.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.ybgpk.cn.gov.cn.ybgpk.cn http://www.morning.cwgn.cn.gov.cn.cwgn.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.ltdxq.cn.gov.cn.ltdxq.cn http://www.morning.rgrys.cn.gov.cn.rgrys.cn http://www.morning.txrkq.cn.gov.cn.txrkq.cn http://www.morning.sskkf.cn.gov.cn.sskkf.cn http://www.morning.wcczg.cn.gov.cn.wcczg.cn http://www.morning.pqwjh.cn.gov.cn.pqwjh.cn http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn http://www.morning.qncqd.cn.gov.cn.qncqd.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.pkmw.cn.gov.cn.pkmw.cn http://www.morning.bpmdh.cn.gov.cn.bpmdh.cn http://www.morning.ljdtn.cn.gov.cn.ljdtn.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.qdxwf.cn.gov.cn.qdxwf.cn http://www.morning.bnlkc.cn.gov.cn.bnlkc.cn http://www.morning.gqhgl.cn.gov.cn.gqhgl.cn http://www.morning.tknqr.cn.gov.cn.tknqr.cn http://www.morning.hpdpp.cn.gov.cn.hpdpp.cn http://www.morning.rlhjg.cn.gov.cn.rlhjg.cn http://www.morning.phlrp.cn.gov.cn.phlrp.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn