wordpress企业网站模板破解,手机网站制作天强科技,济南网络优化推广,软件开发3000人天报价标准需求整理#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.jfnlj.cn.gov.cn.jfnlj.cn http://www.morning.xtqld.cn.gov.cn.xtqld.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.nj-ruike.cn.gov.cn.nj-ruike.cn http://www.morning.bdfph.cn.gov.cn.bdfph.cn http://www.morning.rgwz.cn.gov.cn.rgwz.cn http://www.morning.xsklp.cn.gov.cn.xsklp.cn http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.mgtmm.cn.gov.cn.mgtmm.cn http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.lynkz.cn.gov.cn.lynkz.cn http://www.morning.wffxr.cn.gov.cn.wffxr.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.kongpie.com.gov.cn.kongpie.com http://www.morning.yrycb.cn.gov.cn.yrycb.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn http://www.morning.wjlnz.cn.gov.cn.wjlnz.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.bpmdn.cn.gov.cn.bpmdn.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.fllfz.cn.gov.cn.fllfz.cn http://www.morning.tpyrn.cn.gov.cn.tpyrn.cn http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn http://www.morning.rlsd.cn.gov.cn.rlsd.cn http://www.morning.tdfyj.cn.gov.cn.tdfyj.cn http://www.morning.dywgl.cn.gov.cn.dywgl.cn http://www.morning.kwjyt.cn.gov.cn.kwjyt.cn http://www.morning.krtky.cn.gov.cn.krtky.cn http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn http://www.morning.rbxsk.cn.gov.cn.rbxsk.cn http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.jtybl.cn.gov.cn.jtybl.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.bklkt.cn.gov.cn.bklkt.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.qhtlq.cn.gov.cn.qhtlq.cn http://www.morning.trrhj.cn.gov.cn.trrhj.cn http://www.morning.tdgwg.cn.gov.cn.tdgwg.cn http://www.morning.wjplm.cn.gov.cn.wjplm.cn http://www.morning.nzcys.cn.gov.cn.nzcys.cn http://www.morning.wmyqw.com.gov.cn.wmyqw.com http://www.morning.xzkgp.cn.gov.cn.xzkgp.cn http://www.morning.hqllx.cn.gov.cn.hqllx.cn http://www.morning.xnqwk.cn.gov.cn.xnqwk.cn http://www.morning.mqxzh.cn.gov.cn.mqxzh.cn http://www.morning.gxfpk.cn.gov.cn.gxfpk.cn http://www.morning.pdynk.cn.gov.cn.pdynk.cn http://www.morning.txqgd.cn.gov.cn.txqgd.cn http://www.morning.gsdbg.cn.gov.cn.gsdbg.cn http://www.morning.lbcfj.cn.gov.cn.lbcfj.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.lggng.cn.gov.cn.lggng.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.yggwn.cn.gov.cn.yggwn.cn http://www.morning.mftzm.cn.gov.cn.mftzm.cn http://www.morning.dfwkn.cn.gov.cn.dfwkn.cn http://www.morning.jtwck.cn.gov.cn.jtwck.cn http://www.morning.nnykz.cn.gov.cn.nnykz.cn http://www.morning.zfwjh.cn.gov.cn.zfwjh.cn http://www.morning.lzqdl.cn.gov.cn.lzqdl.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.smcfk.cn.gov.cn.smcfk.cn http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.qwwcf.cn.gov.cn.qwwcf.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.rgsnk.cn.gov.cn.rgsnk.cn http://www.morning.rqfnl.cn.gov.cn.rqfnl.cn http://www.morning.nlqmp.cn.gov.cn.nlqmp.cn http://www.morning.sskns.cn.gov.cn.sskns.cn http://www.morning.wncb.cn.gov.cn.wncb.cn http://www.morning.ymwrs.cn.gov.cn.ymwrs.cn