当前位置:网站首页>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
边栏推荐
- Timer和ScheduledThreadPoolExecutor的区别
- Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
- Difficult to get up syndrome (bit by bit greed)
- Accelerator systems initiative is an independent non-profit organization
- .env.xxx 文件,加了常量,卻undefined
- Using SqlCommand objects in code
- SQL Server 安裝指南
- I would like to ask, which securities is better for securities account opening? Is it safe to open a mobile account?
- 【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
- Key points of security agreement
猜你喜欢
PWN attack and defense world cgpwn2
[QT] qtcreator uninstall and installation (abnormal state)
【CMake】Qt creator 里面的 cmake 配置
2022拼多多详情/拼多多商品详情/拼多多sku详情
Heketi record
[embedded system course design] a single key controls the LED light
Key points of security agreement
E-commerce RPA robot helps brand e-commerce to achieve high traffic
Leetcode medium question sharing (5)
S32Kxxx bootloader之UDS bootloader
随机推荐
Is it safe and reliable to open an account in Caixue school and make new debts?
牛客-练习赛101-推理小丑
下载在线视频 m3u8使用教程
【QT】测试Qt是否能连接上数据库
The origin of usb-if Association and various interfaces
Resumption of attack and defense drill
九州云与英特尔联合发布智慧校园私有云框架,赋能教育新基建
Review data desensitization system
二叉搜索树的创建,查找,添加,删除操作
【QT】Qt 使用MSVC2017找不到编译器的解决办法
比较通俗易懂的PID理解
RPA tutorial 01: Excel automation from introduction to practice
关联性——组内相关系数
Node——Egg 创建本地文件访问接口
PyTorch学习记录
heketi 记录
It's nothing to be utilitarian!
智能运维实战:银行业务流程及单笔交易追踪
启牛商学院给的证券账户安不安全?哪里可以开户
使用htaccess文件禁止目录里的脚本执行权限