当前位置:网站首页>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
边栏推荐
- 攻防演练复盘
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- Accelerator systems initiative is an independent non-profit organization
- export default 导出的对象,不能解构问题,和module.exports的区别
- leetcode96不同的二叉搜索樹
- Using SqlCommand objects in code
- 求逆序数的三个方法
- PyTorch学习记录
- 在证券账户上买基金安全吗?哪里可以买基金
- Material design component - use bottomsheet to show extended content (I)
猜你喜欢
SQL数据分析之流程控制语句【if,case...when详解】
Asp .NetCore 微信订阅号自动回复之文本篇
Heketi record
Practical calculation of the whole process of operational amplifier hysteresis comparator
数据分析方法论与前人经验总结【笔记干货】
leetcode96不同的二叉搜索树
LDR6035智能蓝牙音响可对手机设备持续充放电方案
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Multi table operation - one to one, one to many and many to many
[QT] qtcreator uninstall and installation (abnormal state)
随机推荐
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Node——Egg 创建本地文件访问接口
[embedded system course design] a single key controls the LED light
What is ThreadLocal memory leak and how to solve it
Operate database transactions with jpatractionmanager
【QT】QtCreator卸载与安装(非正常状态)
LeetCode 0241.为运算表达式设计优先级 - DFS
挖财学堂开户打新债安全可靠嘛?
Is the securities account given by qiniu business school safe? Where can I open an account
The difference between timer and scheduledthreadpoolexecutor
When installing mysql, there are two packages: Perl (data:: dumper) and Perl (JSON)
Asp .NetCore 微信订阅号自动回复之文本篇
Ldr6035 smart Bluetooth audio can continuously charge and discharge mobile devices
Leetcode medium question sharing (5)
【QT】对于Qt MSVC 2017无法编译的问题解决
How to improve data quality
Iota in golang
Review data desensitization system
Record the accidental success and failure of uploading large files
ThreadLocal内存泄漏是什么,怎么解决