当前位置:网站首页>Use es to realize epidemic map or take out order function (including code and data)
Use es to realize epidemic map or take out order function (including code and data)
2022-07-02 00:19:00 【Elastic open source community】
0、 introduction
The current situation , We use the relevant functions of the epidemic map almost every day , The core function is geographic location retrieval , Use ES Can be very easy to achieve , Let me briefly talk about how to design and implement several core functions .
This article does not cover the preceding paragraph UI Design and implementation of and client call code , If everyone needs , You can leave me a message , If the demand is relatively large, you can consider making a complete project open source , Like it and support it
PS: To study this article, we need to know something about Elasticsearch Location search Have a certain understanding of the basic functions of , Recommended reading :todo
The data used in this case , You can download it at the end of the article .
1、 Function module
The following figure shows the basic block of the epidemic map , The purpose of this paper is to apply geographical location retrieval to project landing , Therefore, business modules unrelated to core functions will not be listed . The main functions are shown in the figure 
The main functions include :
- Administrative region information entry
- Institutional information
- Health code status reporting
- Search for nearby nucleic acid testing institutions ( The hospital )
- Check the number of confirmed cases in a certain area ( Within the Administrative Region )
- Query the distribution of confirmed persons in a certain area
- Query the administrative region of a hospital
- Count the number of confirmed cases in cities in various provinces
2、 Index structure design
2.1 Regional index
The linkage between provinces and cities is very common in many scenes , Its table structure is also very simple , Through one pid perhaps pcode You can save the cascading relationship .
But when searching geographical location , There is only Spatial relations There is no such thing as logical relationship , Different geographical locations do not save their relationships through associated fields , So when designing the index , Whether the province or city adopts structured logical storage , It depends on the business . Only from the geographical location retrieval analysis , No matter the province 、 City 、 Area or street , They all belong to Geometry , So there is no need for structured storage , Every _doc Save one geo_shape That is a reasonable way .
I still retain the logical relationship between provinces and cities , But this is not useful for the functions to be realized in this paper . It is recommended that each province be included in the index 、 City 、 region 、 Create a separate document for the street , Use polygon Storage .
ES Support only basic geometry , Irregular geometry is not supported , How to store such graphics in provinces and regions ?
In fact, irregular geometry can be regarded as polygons with many sides , There are enough sides , It can accurately describe an irregular polygon . This is actually the same as when you play games , Some scenes that need to display curves , In fact, it is described by countless polygons , When the number of sides is enough , You can't see that he is a polygon .
Indexes mapping
PUT area
{
"mappings": {
"properties": {
"location": {
"type": "geo_shape"
},
"city": {
"properties": {
"location": {
"type": "geo_shape"
},
"district": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
}
}
}
}
2.2 Institutional index
The organization can be : The hospital 、 School 、 bridge 、 company 、 Any unit such as tunnel , The specific content depends on what you want to search when you do the function , Generally, the mechanism is a point coordinate , namely :geo_shape:point. To simplify the code , I only store one hospital information here , It can also be understood as the network of nucleic acid testing institutions .
Indexes mapping as follows :
PUT hospital
{
"mappings": {
"properties": {
"properties" : {
"address" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"district" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"location" : {
"type" : "geo_shape"
},
"lv" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
2.3 Personnel information index ( Report information )
Personnel information reporting actually includes health codes 、 Trip code ( Trajectory )、 Nucleic acid test report 、 Health status and other information , Information reporting basically takes place in the access control code scanning registration 、 The time when the nucleic acid test results occur , The travel trajectory reporting time can be calculated and reported by changing the base station connected to the mobile phone . In order to simplify the function , Only one status field is reserved for our personnel's health information : And health or infection ( Diagnosis ).
Indexes mapping:
PUT case_person
{
"mappings": {
"properties": {
"date": {
"type": "date"
},
"location": {
"type": "geo_shape"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
3、 Realization
3.1 Statistics of new items on the current day
Here is just a simple statistic , No longer distinguish between native 、 foreign 、 Asymptomatic and other business fields , Statistics of new items on the current day , It means satisfaction
- The time of diagnosis is the same day
- The status is confirmed
All personnel information of two conditions , The code is as follows :
GET case_person/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"date": {
"gte": "now/d"
}
}},
{
"term": {
"status.keyword": {
"value": " Diagnosis "
}
}
}
]
}
},
"aggs": {
"today_add": {
"value_count": {
"field": "status.keyword"
}
}
}
}
3.2 Check the surrounding confirmed cases
Inquire about the confirmed cases in the surrounding areas or the confirmed cases in the Administrative Region , It can be applied to businesses such as judging whether the region belongs to medium and high risk areas , It's also very simple to implement . Just provide two conditions
- Current longitude and latitude coordinates
- Search radius
If it's in APP in , The current coordinate is directly called SDK The location interface provided in , If it is for testing , The coordinates can be obtained by selecting points on the map through the open interface provided by Baidu map . The operation steps are: :
Scrolling pages , Find the development documentation section of the page , Click the coordinate picker 
here , Real time coordinates will be displayed where the mouse passes in the map :

You can choose your favorite coordinates in the map , Simulate your current position . For example, the longitude and latitude of my current position is :
- “lon”:116.238334,
- “lat”:39.900112
Take Yonghui supermarket as the center of the circle , The radius is three kilometers , Search for Amusement park... Octagonal 、 Babaoshan 、 Yuquan Road 、 Wukesong has four subway stations ( The subway station here can be regarded as a confirmed case ), That is, there are four confirmed cases within three kilometers .
Such a search , It can also be used to search nearby nucleic acid detection institutions : The code is as follows :
3.2 Search the specified units in the specified area
Search for units in the specified area , You can search various units , You can also search various administrative regions .
For example, search Beijing - All nucleic acid testing institutions in Haidian District :
The code is as follows :
GET province_bak/_search
{
"query": {
"term": {
"name.keyword": {
"value": " Haidian District "
}
}
}
}
GET hospital/_search
{
"_source": {
"include":["name","district"]},
"query": {
"geo_shape": {
"location": {
"indexed_shape": {
"index": "province_bak",
"id": "110108",
"path": "location"
},
"relation": "within"
}
}
}
}
Index data download :https://t.zsxq.com/037YJUJia
边栏推荐
- Which app is better and more secure for stock mobile account opening
- export default 导出的对象,不能解构问题,和module.exports的区别
- Regular expression collection
- 挖财学堂开户打新债安全可靠嘛?
- 如何提升数据质量
- Soft exam information system project manager_ Compiled abbreviations of the top ten management processes to help memory recitation - -- software test advanced information system project manager 054
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- 起床困难综合症(按位贪心)
- 微信小程序缓存过期时间的相关设置(推荐)
- SQL Server Installation Guide
猜你喜欢

时间复杂度与空间复杂度

LDR6035智能蓝牙音响可充可放(5.9.12.15.20V)快充快放设备充电

基于全志H3的QT5.12.9移植教程

Use pair to do unordered_ Key value of map

Database -- sqlserver details

Download the online video m3u8 tutorial

Qt5.12.9 migration tutorial based on Quanzhi H3
![[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler](/img/35/e458fd437a0bed4bace2d6d65c9ec8.png)
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler

Shell process control

Windows installation WSL (II)
随机推荐
Qt5.12.9 migration tutorial based on Quanzhi H3
js 公共库 cdn 推荐
Node——生成微信权限验证配置
SQL Server Installation Guide
Data analysis methodology and previous experience summary [notes dry goods]
Ldr6035 smart Bluetooth audio can be charged and released (5.9.12.15.20v) fast charging and fast releasing device charging
在证券账户上买基金安全吗?哪里可以买基金
Node——Egg 创建本地文件访问接口
Halcon knowledge: an attempt of 3D reconstruction
Comprehensive usage and case questions of sub query of SQL data analysis [patient sorting]
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
【QT】Qt 使用MSVC2017找不到编译器的解决办法
攻防演练复盘
Material design component - use bottomsheet to show extended content (I)
Relevant settings of wechat applet cache expiration time (recommended)
An intern's journey to cnosdb
电商RPA机器人,助力品牌电商抢立流量高点
Is the securities account given by qiniu business school safe? Where can I open an account
ADO. Net SqlCommand object
- Oui. Env. Fichier XXX, avec constante, mais non spécifié