当前位置:网站首页>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
边栏推荐
- 一个实习生的CnosDB之旅
- Difficult to get up syndrome (bit by bit greed)
- 挖财学堂开户打新债安全可靠嘛?
- Qt5.12.9 migration tutorial based on Quanzhi H3
- vs2015 AdminDeployment. xml
- ADO. Net SqlDataAdapter object
- PHP reads ini or env type configuration
- Multi table operation - one to one, one to many and many to many
- Linux CentOS7安装Oracle11g的超完美新手教程
- 起床困难综合症(按位贪心)
猜你喜欢

PyTorch学习记录

leetcode96不同的二叉搜索樹

电商RPA机器人,助力品牌电商抢立流量高点

Intelligent operation and maintenance practice: banking business process and single transaction tracking

Review data desensitization system

GCC compilation

What is ThreadLocal memory leak and how to solve it

heketi 记录

Key points of security agreement

【CMake】Qt creator 里面的 cmake 配置
随机推荐
vue 强制清理浏览器缓存
Intelligent operation and maintenance practice: banking business process and single transaction tracking
Graduation season is both a farewell and a new beginning
【QT】對於Qt MSVC 2017無法編譯的問題解决
在证券账户上买基金安全吗?哪里可以买基金
九州云与英特尔联合发布智慧校园私有云框架,赋能教育新基建
heketi 记录
数据库--SqlServer详解
Practical calculation of the whole process of operational amplifier hysteresis comparator
export default 导出的对象,不能解构问题,和module.exports的区别
leetcode96不同的二叉搜索树
An intern's journey to cnosdb
Asp .NetCore 微信订阅号自动回复之文本篇
Take the enclave Park as a sample to see how Yuhua and Shaoshan play the song of Chang Zhu Tan integrated development
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Difficult to get up syndrome (bit by bit greed)
ThreadLocal内存泄漏是什么,怎么解决
RPA tutorial 01: Excel automation from introduction to practice
回顾数据脱敏系统
- Oui. Env. Fichier XXX, avec constante, mais non spécifié